在.NET中我正在运行这条线
var p = Process.Start(@"cmd", @"/C mklink /H c:\z\b c:\z\a\");
Run Code Online (Sandbox Code Playgroud)
这一切正常,但我担心如果 mklink 的两个参数之一有空格,这将无法正常工作。所以我在两个参数周围添加了“”。执行这一行不再起作用,当我写 \"" 时,它仍然不起作用。
执行时如何写引号cmd /C?
string sourcePath = @"c:\z\b";
string targetPath = @"c:\z\a";
string arguments = string.Format("\"{0}\" \"{1}\"", sourcePath, targetPath);
var p = Process.Start("cmd", "/C mklink /H " + arguments);
Run Code Online (Sandbox Code Playgroud)
工作示例:
string sourcePath = @"c:\documents and settings\harvey robert\My Documents\Test.txt";
string targetPath = @"c:\test";
string s = string.Format("\"{0}\" \"{1}\"", sourcePath, targetPath);
Process.Start("cmd", @"/c copy " + s);
Run Code Online (Sandbox Code Playgroud)
复制了 1 个文件。