当前位置:编程学习 > C#/ASP.NET >>

C# 调用CMD.exe执行help命令程序卡住了,其他的命令没有问题

大家好:
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的时候程序卡住不动了,请问为什么? --------------------编程问答-------------------- p.WaitForExit();//将这句注释掉 --------------------编程问答--------------------
引用 1 楼 hjywyj 的回复:
p.WaitForExit();//将这句注释掉

注释掉后问题仍然存在。 --------------------编程问答-------------------- p.StartInfo.RedirectStandardOutput = true; 

这里阻塞了,你需要用异步的输出 --------------------编程问答--------------------
引用 3 楼 fangxinggood 的回复:
p.StartInfo.RedirectStandardOutput = true; 

这里阻塞了,你需要用异步的输出
那为什么我执行其他的命令都没有问题如ipconfig,dir而单单执行help的时候出问题了? --------------------编程问答--------------------
引用 2 楼 uu_bird1 的回复:
引用 1 楼 hjywyj 的回复:p.WaitForExit();//将这句注释掉
注释掉后问题仍然存在。

你传递的什么参数?
去掉p.WaitForExit();之后我这里调试没问题
ExecuteCmd("help"); --------------------编程问答--------------------
引用 3 楼 fangxinggood 的回复:
p.StartInfo.RedirectStandardOutput = true; 

这里阻塞了,你需要用异步的输出
修改后发现不是这里的问题 --------------------编程问答--------------------
引用 5 楼 hjywyj 的回复:
引用 2 楼 uu_bird1 的回复:引用 1 楼 hjywyj 的回复:p.WaitForExit();//将这句注释掉
注释掉后问题仍然存在。
你传递的什么参数?
去掉p.WaitForExit();之后我这里调试没问题
ExecuteCmd("help");
真奇怪,在我这里就有问题。。。。奇怪。 --------------------编程问答-------------------- --------------------编程问答--------------------
引用 8 楼 hjywyj 的回复:
刚调试通过,你是对的,【刚才的错误时因为我改动的时候又加了一句p.standError】,不好意思啊,兄弟,你是对的。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,