ResGen.exe stucks when redirect output

前端 未结 2 1953
借酒劲吻你
借酒劲吻你 2021-01-20 21:38

I try to redirect standard output from ResGen.exe. I use following code

ProcessStartInfo psi = new ProcessStartInfo( \"resxGen.exe\" );
psi.CreateNoWindow =          


        
2条回答
  •  广开言路
    2021-01-20 22:21

    The bottom line would seem to be that the placement of p.WaitForExitis incorrect; this method call should be made only after reading what you want from the stream.

    From MSDN:

     // Start the child process.
     Process p = new Process();
     // Redirect the output stream of the child process.
     p.StartInfo.UseShellExecute = false;
     p.StartInfo.RedirectStandardOutput = true;
     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.
     // p.WaitForExit();
     // Read the output stream first and then wait.
     string output = p.StandardOutput.ReadToEnd();
     p.WaitForExit();
    

    Also note that your use of StreamReader sr = p.StandardOutput is redundant here since when the value ofmessage is set you access the stream using p.StandardOutput.ReadToEnd(); - note the p.StandardOutput as opposed to sr.ReadToEnd().

提交回复
热议问题