【问题标题】:Application Freezes on "StandardOutput.ReadLine()".应用程序在“StandardOutput.ReadLine()”上冻结。
【发布时间】:2012-04-23 12:51:39
【问题描述】:

应用程序在尝试调用“StandardOutput.ReadLine()”时挂起。

代码:

ProcessStartInfo startInfo = new ProcessStartInfo("c:\\windows\\system32\\myTesting.exe");
            String s = " ";

            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.CreateNoWindow = true;
            startInfo.RedirectStandardInput = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute = false;
            Process p = Process.Start(startInfo);
            p.StandardInput.WriteLine("list volume\n");
            String f = "";

            while (!p.StandardOutput.EndOfStream)
                {
                    s = p.StandardOutput.ReadLine();
                }

“死锁异常”——错误有时会发生,但并非总是如此。

【问题讨论】:

标签: c# asp.net multithreading c#-4.0 process


【解决方案1】:

也许是这个问题。试试这个:

// Create the child process.
 Process p = new Process();

 // Redirect the output stream of the child process.
 p.StartInfo.UseShellExecute = false;
 p.StartInfo.RedirectStandardOutput = true;

 //setting the application path
 p.StartInfo.FileName = "Write500Lines.exe";
 p.Start();

 // Do not wait for the child process to exit before
 // reading to the end of its redirected stream.
 // Read the output stream first and then wait.
 string output = p.StandardOutput.ReadToEnd();
 p.WaitForExit();

【讨论】:

  • 您能否包含一些说明您的代码的叙述,以便 OP 知道您做了什么以及为什么这是他们问题的答案?
猜你喜欢
  • 2016-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多