简体   繁体   English

C#Process.Start:Whitespace甚至没有工作

[英]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? 怎么了?

您需要在程序路径中使用两个“空格:

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

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 cmd.exe会将其翻译为

C:/Program Files/nodejs/node.exe" "C:/rc/rainingchain/app.js That's why it complain errors. C:/Program Files/nodejs/node.exe" "C:/rc/rainingchain/app.js这就是为什么它抱怨错误。

What you need is to enclose whole node.exe command with double quote again. 你需要的是再次用双引号括起整个node.exe命令。

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" 所以node.exe命令将是"C:/Program Files/nodejs/node.exe" "C:/rc/rainingchain/app.js"

BTW, why don't just call node.exe directly? 顺便说一下,为什么不直接调用node.exe?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM