Trouble calling upon two arguments

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
iampedro
Posts: 5
Joined: Wed Dec 18, 2013 12:40 pm

Trouble calling upon two arguments

Post by iampedro » Wed Aug 01, 2018 9:25 am

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..

User avatar
jvierra
Posts: 13725
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Trouble calling upon two arguments

Post by jvierra » Wed Aug 01, 2018 9:35 am

$dataup = "C:\Program Files (x86)\R.O. Writer\dataup.exe"
Start-Process $dataup -ArgumentList '/2 /Y'


Needs quotes.

User avatar
mxtrinidad
Site Admin
Posts: 328
Joined: Sun Mar 03, 2013 12:42 pm

Re: Trouble calling upon two arguments

Post by mxtrinidad » Wed Aug 01, 2018 10:23 am

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'.

:)

User avatar
jvierra
Posts: 13725
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Trouble calling upon two arguments

Post by jvierra » Wed Aug 01, 2018 10:45 am

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.

User avatar
jvierra
Posts: 13725
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Trouble calling upon two arguments

Post by jvierra » Wed Aug 01, 2018 10:46 am

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.

Locked