I am executing a program through Process.Start()
. I tried redirecting the output to get the lines.
For now, however, I only need the last line.
Is there a way to read the last line only or do I still need to the whole redirectStandaroutput = false;
etc?
Is there a simpler way?
If I have to go by the process.Redirect()
, I tried following the examples on MSDN and other sources with outputdatareceived
event, but my output only gets written to the console at the end and is not async.
Once you use process.Start()
the only way to read output that I know is to use .RedirectStandardInput = true;
.
And as Standart output is a stream object, last line could be read only by reading whole stream.
BTW proc.StandardOutput.ReadToEnd()
will hang your thread untill process will exit, and if you'll get any promts during reading - your app will hang up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With