0

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

「デッドロック例外」エラーが発生することがありますが、常に発生するわけではありません。

4

1 に答える 1

0

wihleが問題です。これを試してみてください:

// 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();
于 2012-04-23T12:55:42.963 に答える