A group blog from members of the VB team
It's common that you want to launch an external process but supply input and capture the output. Here's one attempt:
' BAD CODE
Using p As New System.Diagnostics.Process
p.StartInfo.FileName = "cat"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardInput = True
p.StandardInput.Write("world" & vbCrLf & "hello")
Dim op = p.StandardOutput.ReadToEnd()
Console.WriteLine("OUTPUT:") : Console.WriteLine(op)
This code has a deadlock bug in it. That's because of the possibility that "p" needs to write to StandardOutput before it's yet finished reading all of StandardInput: there won't be anyone to read from StandardOutput, and it might fill up!
The MSDN documentation says that the answer is to use multiple threads. So here's code that uses multiple threads to avoid the deadlock: http://blogs.msdn.com/lucian/archive/2008/12/29/system-diagnostics-process-redirect-standardinput-standardoutput-standarderror.aspx
PingBack from http://www.codedstyle.com/systemdiagnosticsprocess-avoid-deadlocks-in-redirectstandardinputoutput-lucian-wischik/
The code has another bug. The sub-process executed could hang or go into an infinite loop and never terminate.
This is the basic case of not blocking on a subprocess by creating a thread to load and execute it. It has nothing really to do with standard input and standard output.
P.s. Thanks for referring to the old unix cat utility. I've used many of them, sed and tiffcp especially, for processing data from within a .net application.