sof*_*fun 4 c# system.diagnostics process
我在命令行中运行此应用程序并获得所需的结果
Helpdesk-02.exe /department it
Run Code Online (Sandbox Code Playgroud)
但是我的C#代码(下面)似乎忽略了参数,但是在没有命令行开关的情况下启动应用程序
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = @"Y:\Helpdesk-02.exe";
psi.Arguments = @"/department it";
psi.UseShellExecute = true;
Process.Start(psi).WaitForExit();
Run Code Online (Sandbox Code Playgroud)
该@字符是一个特殊的引用字符串,因此它的行为与标准字符串不同.从本质上讲,正在发生的过程是从命令行看起来像这样的过程:
> Helpdesk-02.exe "/department it"
Run Code Online (Sandbox Code Playgroud)
或者一个论点.删除@符号会强制C#按预期解释字符串:
> Helpdesk-02.exe /department it
Run Code Online (Sandbox Code Playgroud)
一个微妙但关键的区别.
该@操作符旨在使更容易使用具有嵌入空格,反斜杠和其他必须在标准字符串中转义的字符的路径.从本质上讲,它会为你逃脱角色.这两个声明是等价的:
string pathToExplorer = @"C:\Program Files\Internet Explorer\iexplore.exe";
string escaped = "\"C:\\Program Files\\Internet Explorer\\iexplore.exe\"";
Run Code Online (Sandbox Code Playgroud)
最好只在使用@文件路径时使用运算符,并在处理参数时使用常规方法.