How to Call dos command like "ping 10.0.0.1" and trace the respond?

  • Thread starter Thread starter James Pang
  • Start date Start date
Hey,

Use System.Diagnostics.Process class that will run a process.

Than redirect its output by setting the process
StartInfo.RedirectStandardOutput = true.

this Will redirect the output to the process instance and then you can use
basic streaming mechanism to trace the respond.

-Moty-
 
thank you

--
Tech Servant James Pang.
Moty Michaely said:
Hey,

Use System.Diagnostics.Process class that will run a process.

Than redirect its output by setting the process
StartInfo.RedirectStandardOutput = true.

this Will redirect the output to the process instance and then you can use
basic streaming mechanism to trace the respond.

-Moty-
 
Hey thank you very much but

myProcess.StartInfo.FileName==@"C:\WINDOWS\system32\ping.exe 10.0.0.1";
//this will not work cant find file name...

myProcess.StartInfo.FileName==@"C:\WINDOWS\system32\ping.exe"; //this works
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.Verb="10.0.0.1";

// myProcess.StartInfo.Verb = "Print";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.UseShellExecute=false;
myProcess.Start();



string output =myProcess.StandardOutput.ReadToEnd();
System.Console.WriteLine(output);
 
Right..

You must use Arguments property for your purpose.

myProcess.FileName = @"C:\Windows\System32\Ping.exe"
myProcess.Arguments = "10.0.0.1"

using Verb property is not so good option I think.

If it works for you, great.

- Moty -
 
Back
Top