在C#中執(zhí)行批處理文件我試圖在C#中執(zhí)行一個批處理文件,但是我沒有任何運氣。我在互聯(lián)網(wǎng)上找到了很多這樣做的例子,但這對我沒有用。public void ExecuteCommand(string command){
int ExitCode;
ProcessStartInfo ProcessInfo;
Process Process;
ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = false;
Process = Process.Start(ProcessInfo);
Process.WaitForExit();
ExitCode = Process.ExitCode;
Process.Close();
MessageBox.Show("ExitCode: " + ExitCode.ToString(), "ExecuteCommand");}命令字符串包含批處理文件的名稱(存儲在system32)以及它應(yīng)該操作的一些文件。(例如:txtmanipulator file1.txt file2.txt file3.txt)。當(dāng)我手動執(zhí)行批處理文件時,它工作正常。在執(zhí)行代碼時,它給了我一個**ExitCode: 1** (Catch all for general errors)我做錯什么了?
3 回答

慕的地8271018
TA貢獻1796條經(jīng)驗 獲得超4個贊
System.Diagnostics.Process.Start("c:\\batchfilename.bat");
- 3 回答
- 0 關(guān)注
- 710 瀏覽
添加回答
舉報
0/150
提交
取消