Passing quotes in Process.Start arguments

后端 未结 1 848
既然无缘
既然无缘 2020-12-02 02:02

In .NET i\'m running this line

var p = Process.Start(@\"cmd\", @\"/C mklink /H c:\\z\\b c:\\z\\a\\\");

This works all fine however I\'m wor

相关标签:
1条回答
  • 2020-12-02 03:05
    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);
    

    Working example:

    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);
    

    1 files copied.

    0 讨论(0)
提交回复
热议问题