C# Process Start needs Arguments with double quotes - they disappear

喜欢而已 提交于 2019-12-01 03:48:09
TaRDy

Quotes in ProcessStartInfo.Arguments must be escaped as three quotes ("""). This is because a single quote is used for passing a string containing spaces as a single argument.

See the documentation here: https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.arguments(v=vs.110).aspx

ProcessStartInfo psi = new ProcessStartInfo("cmd_app.exe", "\"\"\"optional1\"\"\" optional1value \"\"\"optional2\"\"\" optional2value");
Process.Start(psi);

All cmd_app.exe does is announce its # of args and what the args are, with this input it displays:

"optional1"
optional1value
"optional2"
optional2value
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!