Re: redicting standard output
- From: wfairl@xxxxxxxxx
- Date: 20 Apr 2006 13:28:55 -0700
No, you just need to read it. I looked at your code from the 19th and
you're still not launching a thread to read from the outputstream.
You need something like this:
Process p = new Process();
p.StartInfo.FileName = "MyProg.exe";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute=false;
if(p.Start())
{
ManualResetEvent readerEvent = new ManualResetEvent(false);
StreamPoller errorPoller = new
StreamPoller(readerEvent,p.StandardOutput);
Thread outputThread = new Thread(new ThreadStart(outputPoller.Poll));
outputThread.Start();
p.WaitForExit();
readerEvent.Set();
...
}
public class StreamPoller
{
ManualResetEvent _readEvent;
StreamReader _reader;
public StreamPoller(ManualResetEvent readEvent,StreamReader reader)
{
_readEvent = readEvent;
_reader = reader;
}
public void Poll()
{
while(true)
{
if(_readEvent.WaitOne(1,true))
{
break;
}
//do whatever you want here with the redirected stdout
Console.Writeline(_reader.ReadLine());
}
}
}
.
- Follow-Ups:
- Re: redicting standard output
- From: Zenon
- Re: redicting standard output
- References:
- redicting standard output
- From: Zenon
- Re: redicting standard output
- From: Jeff Louie
- Re: redicting standard output
- From: Zenon
- redicting standard output
- Prev by Date: Re: Iterate through files
- Next by Date: Trying to use nant to build and link resource files into final product
- Previous by thread: Re: redicting standard output
- Next by thread: Re: redicting standard output
- Index(es):
Relevant Pages
|