C# 控制台用process运行一个程序,并得到返回值
Processda=newProcess();da.StartInfo.FileName="cmd.exe";da.StartInfo.UseShellExecute=f...
Process da = new Process();
da.StartInfo.FileName ="cmd.exe";
da.StartInfo.UseShellExecute = false;
da.StartInfo.RedirectStandardInput = true;
da.StartInfo.RedirectStandardOutput = true;
da.StartInfo.RedirectStandardError = true;
da.StartInfo.CreateNoWindow = true;
da.Start();
da.StandardInput.WriteLine("ping -n 1 192.168.0.1");
string strRst = da.StandardOutput.ReadToEnd();
Console.WriteLine("{0}",strRst); 展开
da.StartInfo.FileName ="cmd.exe";
da.StartInfo.UseShellExecute = false;
da.StartInfo.RedirectStandardInput = true;
da.StartInfo.RedirectStandardOutput = true;
da.StartInfo.RedirectStandardError = true;
da.StartInfo.CreateNoWindow = true;
da.Start();
da.StandardInput.WriteLine("ping -n 1 192.168.0.1");
string strRst = da.StandardOutput.ReadToEnd();
Console.WriteLine("{0}",strRst); 展开
展开全部
Process da = new Process();
da.StartInfo.FileName = "cmd.exe";
da.StartInfo.UseShellExecute = false;
da.StartInfo.RedirectStandardInput = true;
da.StartInfo.RedirectStandardOutput = true;
da.StartInfo.RedirectStandardError = true;
//da.StartInfo.CreateNoWindow = true;
da.Start();
da.StandardInput.WriteLine("ping -n 1 192.168.0.1");
da.StandardInput.WriteLine("exit");
string strRst = da.StandardOutput.ReadToEnd();
Console.WriteLine("{0}", strRst);
da.StartInfo.FileName = "cmd.exe";
da.StartInfo.UseShellExecute = false;
da.StartInfo.RedirectStandardInput = true;
da.StartInfo.RedirectStandardOutput = true;
da.StartInfo.RedirectStandardError = true;
//da.StartInfo.CreateNoWindow = true;
da.Start();
da.StandardInput.WriteLine("ping -n 1 192.168.0.1");
da.StandardInput.WriteLine("exit");
string strRst = da.StandardOutput.ReadToEnd();
Console.WriteLine("{0}", strRst);
更多追问追答
追问
还是不行
追答
Process da = new Process();
da.StartInfo.FileName = "cmd.exe";
da.StartInfo.UseShellExecute = false;
da.StartInfo.RedirectStandardInput = true;
da.StartInfo.RedirectStandardOutput = true;
da.StartInfo.RedirectStandardError = true;
da.StartInfo.CreateNoWindow = true;
da.Start();
da.StandardInput.WriteLine("ping -n 1 192.168.0.1");
da.StandardInput.WriteLine("exit");
string strRst = da.StandardOutput.ReadToEnd();
Console.WriteLine("{0}", strRst);
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
d:\my documents\visual studio 2010\项目\测试\测试\bin\Debug>ping -n 1 192.168.0.1
Pinging 192.168.0.1 with 32 bytes of data:
Request timed out.
Ping statistics for 192.168.0.1:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
d:\my documents\visual studio 2010\项目\测试\测试\bin\Debug>exit
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询