我的项目有问题.我想启动一个进程,7z.exe(控制台版).我尝试过三种不同的东西:
什么都行不通.它始终"等待"过程结束以显示我想要的内容.我没有任何代码可以放,只要你想要我的代码与其中一个列出的东西.谢谢.
编辑:我的代码:
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
this.sr = process.StandardOutput;
while (!sr.EndOfStream)
{
String s = sr.ReadLine();
if (s != "")
{
System.Console.WriteLine(DateTime.Now + " - " + s);
}
}
Run Code Online (Sandbox Code Playgroud)
要么
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += new DataReceivedEventHandler(recieve);
process.StartInfo.CreateNoWindow = true;
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
public void recieve(object e, DataReceivedEventArgs outLine)
{
System.Console.WriteLine(DateTime.Now + " - " + outLine.Data);
}
Run Code Online (Sandbox Code Playgroud)
要么
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start(); …Run Code Online (Sandbox Code Playgroud)