c 呼叫命令列遇到帶空格的路徑

2022-03-28 08:23:31 字數 971 閱讀 4179

想用 c#呼叫如下的dos命令:

c:\program files\common files\system\dbwatcherinstall\dtexec.exe /f  c:\program files\common files\system\dbwatcherinstall\tomsde.dtsx  /conf c:\program files\common files\system\dbwatcherinstall\tomsde.xml

**如下:

//用於執行dos命令的方法

public static string executedoscommand(string doscommand, int milliseconds)

}catch

finally

}return output;

}

一開始把命令拼接成:

"c:\program files\common files\system\dbwatcherinstall\dtexec.exe" /f "c:\program files\common files\system\dbwatcherinstall\tomsde.dtsx" /conf "c:\program files\common files\system\dbwatcherinstall\tomsde.xml"
測試失敗...

經過多次試驗之後, 使用以下方式可以實現:即開頭加乙個@同時使用""將帶空格的路徑包圍起來

@"c:\program files\common files\system\dbwatcherinstall\dtexec.exe" /f "c:\program files\common files\system\dbwatcherinstall\tomsde.dtsx" /conf "c:\program files\common files\system\dbwatcherinstall\tomsde.xml" /de

C 呼叫cmd命令列路徑中帶空格問題

打包winform程式,程式中本身有一處需要呼叫cmd.exe,打包安裝在c program files目錄下,然後呼叫cmd的地方,就彈出了c program不是內部或外部命令,也不是可執行的程式或批處理檔案的錯誤提示框,對比了一下未安裝和安裝之後的指定檔案路徑,發現安裝後的路徑中有空格,然後在網...

C 呼叫cmd命令列路徑中帶空格問題

今天打包winform程式,程式中本身有一處需要呼叫cmd.exe,打包安裝在c program files目錄下,然後呼叫cmd的地方,就彈出了c program不是內部或外部命令,也不是可執行的程式或批處理檔案的錯誤提示框,對比了一下未安裝和安裝之後的指定檔案路徑,發現安裝後的路徑中有空格,然後...

C 呼叫命令列

開關 c表示執行完命令就退出 system.diagnostics.process cmd system.diagnostics.process.start cmd.exe c xcopy c test1 c test2 y q s cmd.waitforexit system.diagnostic...