2011-05-12 215 views
1

可能重複:
batch file execution in c#批處理文件執行

我使用C#中運行Java批處理文件.. 但問題是,它沒有走的路徑 我在代碼中使用如下:

var si = new ProcessStartInfo(); 
      si.CreateNoWindow = true; 
      si.WorkingDirectory = batch_process_path; 
      si.FileName = batch_process_path + "\\" + "run.bat"; 
      si.UseShellExecute = true; 
      Process.Start(si.FileName); 

根據我的邏輯該過程應該從si.working目錄開始。但它從「C:」開始。但如果我給靜態路徑它將成功執行.. 我不明白是什麼問題。 請幫我一把。

+3

您應該使用新信息編輯現有問題,而不是創建新問題。 – 2011-05-12 14:38:55

回答

3

請勿使用batch_process_path + "\\" +改爲使用Path.Combine()以確保路徑正確裝有斜槓。

而且read this「當UseShellExecute爲真時,WorkingDirectory屬性指定可執行文件的位置」

所以其設置爲false。