Trouble calling upon two arguments

Ask your 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.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
iampedro
Posts: 5
Last visit: Tue Aug 27, 2019 6:11 am

Trouble calling upon two arguments

Post 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..
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Trouble calling upon two arguments

Post by jvierra »

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


Needs quotes.
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Trouble calling upon two arguments

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

:)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Trouble calling upon two arguments

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Trouble calling upon two arguments

Post 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.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked