RainingChain
RainingChain

Reputation: 7736

C# Process.Start: Whitespace Not Working Even Quoted

What I got:

Process.Start("cmd.exe", "/K \"C:/Program Files/nodejs/node.exe\" \"C:/rc/rainingchain/app.js\"");

Even though I wrapped the filename with escaped ", it still displays the error:

'C:/Program' is not recognized as an internal or external command, operable program or batch file.

What is wrong?

Upvotes: 4

Views: 1226

Answers (2)

qxg
qxg

Reputation: 7036

You code will be translated to

cmd.exe /K "C:/Program Files/nodejs/node.exe" "C:/rc/rainingchain/app.js"

cmd.exe will translate it to

C:/Program Files/nodejs/node.exe" "C:/rc/rainingchain/app.js That's why it complain errors.

What you need is to enclose whole node.exe command with double quote again.

Process.Start("cmd.exe", "/K \"\"C:/Program Files/nodejs/node.exe\" \"C:/rc/rainingchain/app.js\"\""); so the node.exe command will be "C:/Program Files/nodejs/node.exe" "C:/rc/rainingchain/app.js"

BTW, why don't just call node.exe directly?

Process.Start("C:/Program Files/nodejs/node.exe", "C:/rc/rainingchain/app.js");

Upvotes: 5

Aleksey Shubin
Aleksey Shubin

Reputation: 1998

You need to use two " for spaces in program path:

Process.Start("cmd.exe", "/K \"\"C:/Program Files/nodejs/node.exe\" \"C:/rc/rainingchain/app.js\"\"");

Upvotes: 5

Related Questions