首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

用Process类连续调用Dos命令的有关问题

2012-01-03 
用Process类连续调用Dos命令的问题下面代码只能显示一个Dos命令的结果,想连续显示出第二个Ping的结果应该

用Process类连续调用Dos命令的问题
下面代码只能显示一个Dos命令的结果,想连续显示出第二个Ping的结果应该怎么写?

C# code
 static void Main(string[] args)        {            string output;            using (System.Diagnostics.Process p = new System.Diagnostics.Process())            {                p.StartInfo.FileName = "cmd.exe";                p.StartInfo.Arguments= "/c dir";                p.StartInfo.CreateNoWindow = true;                p.StartInfo.UseShellExecute = false;                p.StartInfo.RedirectStandardInput = true;                p.StartInfo.RedirectStandardOutput = true;                p.StartInfo.RedirectStandardError = true;                p.Start();                output = p.StandardOutput.ReadToEnd();                Console.WriteLine(output);                p.StandardInput.WriteLine("exit");                p.StandardInput.WriteLine("ping 127.0.0.1");                p.StandardInput.WriteLine("exit");                output = p.StandardOutput.ReadToEnd();                Console.WriteLine(output);                p.WaitForExit();            }          }


[解决办法]
引用楼主 Dic4000 的帖子:
下面代码只能显示一个Dos命令的结果,想连续显示出第二个Ping的结果应该怎么写?

C# code
static void Main(string[] args)
{
string output;
using (System.Diagnostics.Process p = new System.Diagnostics.Process())
{
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments= "/c dir";
p.StartInfo.CreateNoW…

[解决办法]
探讨
引用楼主 Dic4000 的帖子:
下面代码只能显示一个Dos命令的结果,想连续显示出第二个Ping的结果应该怎么写?

C# code
static void Main(string[] args)
{
string output;
using (System.Diagnostics.Process p = new System.Diagnostics.Process())
{
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments= "/c dir";

热点排行