bat文件运行一个.exe,然后写入控制台,但是,结果在可执行文件完成后立即返回,而不是在执行过程中返回。
我已经在我的桌面上手动运行了.bat,它工作正常,并逐行返回结果,但是在我的C#应用程序中没有运气。有什么想法吗?
var startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\Desktop\TEST\test.bat"; /
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = false;
startInfo.RedirectStandardOutput = true;
startInfo.WorkingDirectory = @"C:\Desktop\TEST\";
startInfo.RedirectStandardError = true;
using (Process Process = Process.Start(startInfo))
{
using (var reader = (Process.StandardOutput))
{
Console.WriteLine(reader.ReadToEnd());
}
}发布于 2013-07-29 15:23:19
下面的文章应该解释您所看到的行为,ReadToEnd是一个同步操作,BeginOutputReadLine是异步的,因此应该更适合您的需要。
https://stackoverflow.com/questions/17926055
复制相似问题