我有以下代码片段来调用命令行:
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 :(得分:2)
您需要在重定向标准输出时使用输出流:
p.Start();
p.StandardOutput.ReadToEnd();
p.WaitForExit();