2012-04-23 18 views
0

"StandardOutput.ReadLine()"を呼び出すときにアプリケーションがハングします。アプリケーションは "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(); 
       } 

"デッドロック例外" 時に発生する-error、常にではありません。

+0

http://stackoverflow.com/questions/2767496/standardoutput-endofstream-hangs –

答えて

0

ワイルが問題です。ただ、この方法を試してください。

// 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(); 
+0

OPはあなたが何をしたか知っていて、なぜそれが答えはあるので、あなたが、あなたのコードを説明するいくつかの物語を含めることができます彼らの質問に? –

関連する問題