0

Application hangs when attempting to call "StandardOutput.ReadLine()".

The code:

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();
                }

"Deadlock exception"-error occurs sometimes, but not always.

Charp
  • 178
  • 1
  • 2
  • 15
user1351166
  • 11
  • 1
  • 3

1 Answers1

0

perhabs the wihle is the problem. Just try this:

// 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();
HW90
  • 1,953
  • 2
  • 21
  • 44
  • Could you include some narrative explaining your code, so the OP knows what you did and why it is an answer to their question? – Andrew Barber Apr 24 '12 at 06:55