读书人

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

发布时间: 2012-01-03 22:16:06 作者: rapoo

用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";

读书人网 >C#

热点推荐