Use Process.Start with parameters AND spaces in path

后端 未结 4 1710
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 13:33

I\'ve seen similar examples, but can\'t find something exactly like my problem.

I need to run a command like this from C#:

C:\\FOLDER\\folder with sp         


        
4条回答
  •  死守一世寂寞
    2020-12-01 14:14

    You can use the ProcessStartInfo class to separate your arguments, FileName, WorkingDirectory and arguments without worry for spaces

    string fullPath = @"C:\FOLDER\folder with spaces\OTHER_FOLDER\executable.exe"
    ProcessStartInfo psi = new ProcessStartInfo();
    psi.FileName = Path.GetFileName(fullPath);
    psi.WorkingDirectory = Path.GetDirectoryName(fullPath);
    psi.Arguments = "p1=hardCodedv1 p2=" + MakeParameter();
    Process.Start(psi);
    

    where MakeParameter is a function that returns the string to be used for the p2 parameter

提交回复
热议问题