Re: redicting standard output

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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());
}
}
}

.



Relevant Pages

  • Re: What replaces StringBufferInputStream
    ... output stream writer, for that matter) dichotomy. ... has an uderlying input stream which, I imagine, wouldn't be a problem ... underlying OutputStream for a given Writer, ... to a Reader without knowing that the bytes do represent characters ...
    (comp.lang.java.programmer)
  • Re: What replaces StringBufferInputStream
    ... You can create an OutputStream decorator which wraps ... Writer (or an InputStream which wraps a Reader) in just the same way as an ... OutputStreamWriter wraps an OutputStream. ...
    (comp.lang.java.programmer)