c# – 使用Process.Start在路徑中使用引數AND空格
我看過類似的例子,但找不到像我的問題那樣的東西.
我需要從C#執行這樣的命令:
C:\FOLDER\folder with spaces\OTHER_FOLDER\executable.exe p1=hardCodedv1 p2=v2
我在執行時設定v2,所以我需要在呼叫Process.Start之前修改C#中的字串.有誰知道如何處理這個,因為我的引數之間有空格?
類來分隔引數FileName,WorkingDirectory和引數,而不用擔心空格
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);
其中MakeParameter是一個返回要用於p2引數的字串的函式
程式碼日誌版權宣告:
翻譯自:http://stackoverflow.com/questions/17321289/use-process-start-with-parameters-and-spaces-in-path