1

I am using Start-Process with arguments to start a program in powershell.

$ServerToStart = "C:/a/b/c/xyz.exe"

Start-Process $ServerToStart -ArgumentList "a, b, Foo Bar"

Arguments a & b work perfectly, however, the "Bar" of the argument "Foo Bar" is ignored, and only the "Foo" is accepted - presumably because of the space.

How do I solve this in powershell?

3 Answers 3

3

According to PS documentation, "If parameters or parameter values contain a space, they need to be surrounded with escaped double quotes. For more information, see about_Quoting_Rules."

So, in this case I think the right way would be

Start-Process $ServerToStart -ArgumentList "a, b, `"Foo Bar`""
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried encapsulating the argument in quotes:

Start-Process $ServerToStart -ArgumentList "a, b, 'Foo Bar'"

1 Comment

Unfortunately this does not work - it causes everything after the start of the quote to break - as if I've left an open quote.
0

In my experience, this is how it usually works:

$ServerToStart = "C:/a/b/c/xyz.exe"

Start-Process $ServerToStart -ArgumentList "a", "b", "Foo Bar"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.