大家好:
C# 调用CMD.exe执行help命令程序卡住了,其他的命令没有问题上代码:
private void ExecuteCmd(string command)  
{  
Process p = new Process();  
p.StartInfo.FileName = "cmd.exe";  
p.StartInfo.UseShellExecute = false;  
p.StartInfo.RedirectStandardInput = true;  
p.StartInfo.RedirectStandardOutput = true;  
p.StartInfo.CreateNoWindow = true;  
p.Start();  
p.StandardInput.WriteLine(command);  
p.StandardInput.WriteLine("exit");  
p.WaitForExit();  
this.textBox1.Text=textBox1.Text+ p.StandardOutput.ReadToEnd();  
p.Close();  
}  
执行ipconfig,dir等都没有问题,就是执行help的时候程序卡住不动了,请问为什么?

解决方案 »

  1.   

    p.StartInfo.RedirectStandardOutput = true; 这里阻塞了,你需要用异步的输出
      

  2.   

    那为什么我执行其他的命令都没有问题如ipconfig,dir而单单执行help的时候出问题了?
      

  3.   

    你传递的什么参数?
    去掉p.WaitForExit();之后我这里调试没问题
    ExecuteCmd("help");
      

  4.   

    刚调试通过,你是对的,【刚才的错误时因为我改动的时候又加了一句p.standError】,不好意思啊,兄弟,你是对的。