使用ProcessStartInfo
andProcess
我想启动一个程序(例如 getdiff.exe),然后读取该程序产生的所有输出。稍后我将以更具建设性的方式使用数据,现在我只想打印数据以确保其正常工作。但是,程序并没有按应有的方式终止。有人知道为什么吗?提前谢谢你。
ProcessStartInfo psi = new ProcessStartInfo("getdiff.exe");
psi.Arguments = "DIFF";
psi.UseShellExecute = false;
psi.RedirectStandardInput = true;
psi.WorkingDirectory = "c:\\test";
Process p = Process.Start(psi);
string read = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.WriteLine(p);
Console.WriteLine("Complete");
p.Close();
将程序更改为此使其正常工作:
ProcessStartInfo psi = new ProcessStartInfo("getdiff.exe");
psi.Arguments = "DIFF";
psi.UseShellExecute = false;
psi.RedirectStandardInput = true;
psi.WorkingDirectory = "c:\\test";
Process p = Process.Start(psi);
StreamReader read = p.StandardOutput;
while (read.Peek() >= 0)
Console.WriteLine(read.ReadLine());
Console.WriteLine("Complete");
p.WaitForExit();
p.Close();