RedirectStandardOutput From Console

G

Guest

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
 
G

Guest

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top