ResGen.exe stucks when redirect output

前端 未结 2 1973
借酒劲吻你
借酒劲吻你 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:23

    You would need to wait for the process to end after reading the stream, otherwise you have a deadlock in your code. The problem is that your parent process is blocking waiting for the child process to finish, and the child process is waiting for the parent process to read the output, hence you have a deadlock.

    Here is a good and detailed description of the problem.

    Changing your code like this should avoid the deadlock:

    StreamReader sr = p.StandardOutput;
    string message = p.StandardOutput.ReadToEnd();
    p.WaitForExit();
    

提交回复
热议问题