Click here to Skip to main content
15,910,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm using VB.NET 2010 and i want to read console output in real time with buffer.
Because there is some console application that doesn't show line in output until th operation is done.

Any help please!
Posted

1 solution

You can re-direct outputs of the console application into some streams you can provide by yourself. Use System.Diagnostics.Process.Start(ProcessStartInfo).

You can re-direct two output streams: System.Diagnostics.Process.StandardError and System.Diagnostics.Process.StandardOutput. You need to use System.Diagnostics.ProcessStartInfo in order to specify System.Diagnostics.ProcessStartInfo.RedirectStandardError or System.Diagnostics.ProcessStartInfo.RedirectStandardErrorRedirectStandardOutput.

You can use file stream for redirection of StandardError or StandardOutput or some other stream, as these properties should of the type System.IO.StreamReader. You can create your own class derived from System.IO.StreamReader or use its constructor accepting the parameter of the abstract class System.IO.Stream, so you can also use your own stream class derived from System.IO.Stream. In this way, you can implement any stream type to your requirements to be used for stream re-direction.

(One typical example of this re-direction feature is running a compiler or а linker (or other tool used for a build step) under IDE, where a compiler or а linker output (errors and warnings, in particular) is displayed in IDE control immediately as the build goes.)

See:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.stream.aspx[^].

—SA
 
Share this answer
 
Comments
Leecherman 2-Aug-11 0:25am    
I tried to do that but still no output until the application is closed.
some app work normal and display the output, but also some other app doesn't show output until it closed ( but it shows in normal windows command line )

so i have contact the author of the program and he said to me i must use buffer or pipe because some application doesn't show line and the data is saved in VB.NET internal buffer... also he said :
You must read raw data from stream by Read() command.
You should use multi-tread or timer event,
because the Read() stop until data coming.
You keep 1KB size buffer for line by yourself,
and save data each time it reads from stdout stream.

so i don't know how to make it...
So any help please?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900