2009-11-20 73 views
1

我有以下代码片段来调入的命令行:Process.Exited事件不被调用

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

奇怪的是,当[ABC]是一个小的pdf文件(8KB)p_Exited被调用。但是当它是一个大的pdf文件(120kb)时,它永远不会被调用。任何线索?

感谢,

+0

是否永远等待WaitForExit或者它传递线而忽略了事件? – Elisha 2009-11-20 07:55:19

+0

似乎永远等待WaitForExit。两者之间没有发生异常。 – user124858 2009-11-20 08:26:23

+0

这是什么语言?将它包含在标签中会很有帮助! – 2009-11-20 08:47:33

回答

2

需要消耗输出流时的标准输出已经被重定向:

p.Start(); 
p.StandardOutput.ReadToEnd(); 
p.WaitForExit(); 
相关问题