我正在编写一个程序,在其中需要启动cmd并启动批处理文件。问题在于我使用了 MyProcess.WaithForexit();
,我认为它不会等待批处理文件处理完成,而只是等待cmd关闭。到目前为止,我的代码如下:
System.Diagnostics.ProcessStartInfo ProcStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd");
ProcStartInfo.RedirectStandardOutput = true;
ProcStartInfo.UseShellExecute = false;
ProcStartInfo.CreateNoWindow = false;
ProcStartInfo.RedirectStandardError = true;
System.Diagnostics.Process MyProcess = new System.Diagnostics.Process();
ProcStartInfo.Arguments = "/c start batch.bat ";
MyProcess.StartInfo = ProcStartInfo;
MyProcess.Start();
MyProcess.WaitForExit();
我需要等到批处理文件完成。我该怎么做?
start
命令并运行批处理,然后返回结果。 - CodeCaster