I am writing a program in dot net that will execute scripts and command line programs using the framework 2.0's Process object. I want to be able to access the screen buffers of the process in my program. I've investigated this and it appears that I need to access console stdout and stderr buffers. Anyone know how this is accomplished using managed code?
I think I need to use the AttachConsole and the ReadConsoleOutput of the windows console attached to the task in order to read a block of character and attribute data from the console screen. I need to do this is managed code.
See http://msdn.microsoft.com/en-us/library/ms684965(VS.85).aspx
You can accomplish this using the StandardError, StandardOutput, and StandardInput properties on the System.Diagnostics.Process class.
MSDN has a nice example of redirecting standard in and out of a process.
Note that you can only redirect the output of processes that you started. External processes that you didn't launch can't have their stdout redirected after the fact.
Also note that to use StandardInput, you must set ProcessStartInfo.UseShellExecute to false, and you must set ProcessStartInfo.RedirectStandardInput to true. Otherwise, writing to the StandardInput stream throws an exception.
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