How to process a command response in C#?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Weegee
    New Member
    • Mar 2008
    • 13

    How to process a command response in C#?

    Hi,

    Just wondering if anyone knows how to process a command response, such as a "ping", in C#? For example, I know if you make the call, using the System.Diagnost ics namespace, "Process process = Process.Start(" cmd", "/C ping localhost > ping.txt");" starts the command prompt and runs the ping command and then stores the output into the ping.txt file. I'm just wondering if there's a way to avoid the copying of the output to a text file, and routing it to a local string variable in my code, so that I can process it directly? Or is processing the output via the text file the only way?

    Thanks in advanced!
    -Weeg
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Weegee
    Hi,

    Just wondering if anyone knows how to process a command response, such as a "ping", in C#? For example, I know if you make the call, using the System.Diagnost ics namespace, "Process process = Process.Start(" cmd", "/C ping localhost > ping.txt");" starts the command prompt and runs the ping command and then stores the output into the ping.txt file. I'm just wondering if there's a way to avoid the copying of the output to a text file, and routing it to a local string variable in my code, so that I can process it directly? Or is processing the output via the text file the only way?

    Thanks in advanced!
    -Weeg
    [CODE=cpp]Process p = new Process();
    p.StartInfo.Fil eName = "COMMAND";
    p.StartInfo.Arg uments = file;
    p.StartInfo.Use ShellExecute = false;
    p.StartInfo.Red irectStandardOu tput = true;
    p.Start();
    String output = p.StandardOutpu t.ReadToEnd();[/CODE]

    Comment

    Working...