Page 1 of 1

Trouble calling upon two arguments

Posted: Wed Aug 01, 2018 9:25 am
by iampedro
Right now here is what I have,

Code: Select all

$dataup = "C:\Program Files (x86)\R.O. Writer\dataup.exe"
Start-Process $dataup /2/Y
It only call's the /2 not the /Y

Commandline works just fine but not power shell.

What do you suggest...

I have also made variables and then called upon them but still the same thing exist.

Code: Select all

PS C:\> Start-Process $dataup /2/Y
PS C:\> Start-Process $dataup /2 /Y
Start-Process : A positional parameter cannot be found that accepts argument '/Y'.
At line:1 char:1
+ Start-Process $dataup /2 /Y
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand

PS C:\> Start-Process $dataup "/2 /Y"
PS C:\> Start-Process $dataup "/2"+"/Y"
Start-Process : A positional parameter cannot be found that accepts argument '+/Y'.
At line:1 char:1
+ Start-Process $dataup "/2"+"/Y"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand

PS C:\> Start-Process $dataup /2/Y
PS C:\> Start-Process $dataup "/2",/Y
PS C:\> Start-Process $dataup "/2","/Y"
PS C:\> Start-Process $dataup /2;/Y
/Y : The term '/Y' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:26
+ Start-Process $dataup /2;/Y
+                          ~~
    + CategoryInfo          : ObjectNotFound: (/Y:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\> Start-Process $dataup "/2";"/Y"
/Y
PS C:\> Start-Process $dataup '/2';'/Y'
Please advise..

Re: Trouble calling upon two arguments

Posted: Wed Aug 01, 2018 9:35 am
by jvierra
$dataup = "C:\Program Files (x86)\R.O. Writer\dataup.exe"
Start-Process $dataup -ArgumentList '/2 /Y'


Needs quotes.

Re: Trouble calling upon two arguments

Posted: Wed Aug 01, 2018 10:23 am
by mxtrinidad
Keep in mind... Using double-quotes in "/2/Y" it will think the slash is a part of a escape code. To prevent the error you need to use the single-quote in order to accept special characters in the string.

That's why JVierra made the correction from "/2/Y" to use single-quotes '/2/Y'.

:)

Re: Trouble calling upon two arguments

Posted: Wed Aug 01, 2018 10:45 am
by jvierra
Actually I always convert double to single when posting code. I try to entice others to do the same for the reasons Max has noted.
My solution has one error. There should be a space between the two parameters.
Start-Process $dataup -ArgumentList '/2 /Y'

Some commands don't handle switch parameters correctly.

The safest way to send parameters to a command:

$argList = @( '/2','/Y')
Start-Process $dataup -ArgumentList $argList


This guarantees that the command line is parsed and passed correctly.

Re: Trouble calling upon two arguments

Posted: Wed Aug 01, 2018 10:46 am
by jvierra
The users original line Start-Process $dataup "/2 /Y" should have worked. "/2" and "/Y" are not meta characters in PowerShell. PowerShell uses the baqtic character as an escape.

Try it at a prompt:
"/2 /Y" will return unchanged.
"`r`n" will return control characters.
Here is a list of all escaped characters and their meaning: https://ss64.com/ps/syntax-esc.html

One issue with the post is that single and double quotes are their own escapes.
'This '' is a single quote'
"This "" is a double quote"

Using the baqtic here will cause an error.