I have to use an other application (console) to pass some parameter to this program and inside my C# program get the output of that program. I would like not to see the console (all invisible to the user). How can I do that?
+12
A:
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("YOUPROGRAM_CONSOLE.exe" );
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
StreamReader myStreamReader = myProcess.StandardOutput;
string myString = myStreamReader.ReadLine();
Console.WriteLine(myString);
myProcess.Close();
Source : MSDN
Edited: If you require to get the Error Message you will need to use Async operation. You can use asynchronous read operations to avoid these dependencies and their deadlock potential. Alternately, you can avoid the deadlock condition by creating two threads and reading the output of each stream on a separate thread.
Daok
2008-10-11 14:30:25
You'll want to enable "RedirectStandardError" too, and read that stream,In case your sub process generates error messages.
gimel
2008-10-11 15:01:00
I added some information. IN the MSDN it says that it require multiple thread to avoid deadlock.
Daok
2008-10-11 15:21:33