RedirectStandardOutput From Console

Discussion in 'ASP .Net' started by =?Utf-8?B?TW9sZWN1bGFyRnVuaw==?=, Jun 3, 2004.

  1. I'm coding an ASP.NET application using C# in Visual Studio.NET. I've researched the Process class and its associated members extensively, and I'm fairly certain my code is solid.

    I'm attempting to use a streamreader to read the output from an external command line application (grep.exe, in this case, though I've tried it with ipconfig.exe, and I get the same results) using the following code

    Process grep = new Process();
    grep.StartInfo.FileName = "grep.exe"
    grep.StartInfo.Arguments = "-inr \"Foobaroo\" --include=*.foo *.*"

    grep.StartInfo.UseShellExecute = true
    grep.StartInfo.RedirectStandardOutput = true

    grep.Start();

    StreamReader sr = grep.StandardOutput
    string output = sr.ReadLine()
    grep.WaitForExit();

    Response.Write("Filename: " + grep.StartInfo.FileName + "<br>")
    Response.Write("Arguments: " + grep.StartInfo.Arguments + "<br>")
    Response.Write("Output: " + output)

    While the debugging window indicates that I get an exitcode of 0x0, there is no console window that pops up, yet the Output string remains blank. I tried to watch for a new process in the Task Manager, but nothing shows up (not really definitive, but interesting).

    Again, the same thing happens with ipconfig.exe, which I know should produce output (as with this grep app).

    Any thoughts on what may cause these applications, which show textual output when executed from the command line, to fail to generate any output for my application? (A note: My regular expressions are not the issue, of this I am certain

    Thanks, I really appreciate the help

    -- Michael Conove
    Cerner Healthcare Information System
     
    =?Utf-8?B?TW9sZWN1bGFyRnVuaw==?=, Jun 3, 2004
    #1
    1. Advertising

  2. Code Correction

    I apologize, I was debugging in the above code. Here is the actual code I am using (with the UseShellExecute set properly

    Process grep = new Process();
    grep.StartInfo.FileName = "grep.exe"
    grep.StartInfo.Arguments = "-inr \"Foobaroo\" --include=*.foo *.*"

    grep.StartInfo.UseShellExecute = false
    grep.StartInfo.RedirectStandardOutput = true

    grep.Start();

    StreamReader sr = grep.StandardOutput
    string output = sr.ReadLine()
    grep.WaitForExit();

    Response.Write("Filename: " + grep.StartInfo.FileName + "<br>")
    Response.Write("Arguments: " + grep.StartInfo.Arguments + "<br>")
    Response.Write("Output: " + output)


    Cheers!
     
    =?Utf-8?B?TW9sZWN1bGFyRnVuaw==?=, Jun 3, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Finney
    Replies:
    2
    Views:
    1,001
    Egor Bolonev
    Jun 30, 2003
  2. Egor Bolonev
    Replies:
    0
    Views:
    491
    Egor Bolonev
    Jun 30, 2003
  3. Serge Terekhoff
    Replies:
    0
    Views:
    652
    Serge Terekhoff
    Jun 30, 2003
  4. Miktor
    Replies:
    7
    Views:
    12,127
    Joe Bacigalupa
    Aug 9, 2005
  5. Replies:
    5
    Views:
    3,447
    James Kanze
    Mar 4, 2008
Loading...

Share This Page