Process.Exited event is not called

I have the following code snippet to invoke on the command line:

p = new Process(); ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "cmd.exe"; psi.Arguments = "/C " + "type " + "[abc].pdf"; psi.UseShellExecute = false; psi.RedirectStandardInput = false; psi.RedirectStandardOutput = true; psi.CreateNoWindow = true; p.StartInfo = psi; p.EnableRaisingEvents = true; p.Exited += new EventHandler(p_Exited); p.Start(); p.WaitForExit(); 

Strange When [abc] is a small pdf file (8kb) p_Exited . But when it is a large PDF file (120kb), it is never called. Any clues?

Thanks,

+1
command-line c # process
source share
1 answer

You must consume the output when redirecting standard output:

 p.Start(); p.StandardOutput.ReadToEnd(); p.WaitForExit(); 
+2
source share

All Articles