I am launching a process from which I need to capture the Output (typically what you would see if run at the command line) - so I did some digging and found that you can redirect standard output to a stream (which is exactly what I needed).
The some problems arose, specifically I need to ensure the process is hidden (I don't want a command shell opening on top or showing at all, to ensure the ensure can not kill the process by hitting X and for estetics) but it seems to use RedirectStandardOutput I need to ensure that UseShellExecute=false and somehow this now makes the command window appear on screen (as it didn't before I started to try and get my output to redirect.
Why can't I hide the window anymore? Is there another way to do this? I really need to get the output from the process but I don't want it to appear on screen.
Any help would be greatly appreciated.
Thanks,
The some problems arose, specifically I need to ensure the process is hidden (I don't want a command shell opening on top or showing at all, to ensure the ensure can not kill the process by hitting X and for estetics) but it seems to use RedirectStandardOutput I need to ensure that UseShellExecute=false and somehow this now makes the command window appear on screen (as it didn't before I started to try and get my output to redirect.
Code:
Process pProcess = new System.Diagnostics.Process();
pProcess.StartInfo.FileName = sFileName;
pProcess.StartInfo.Arguments = sParameter;
pProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.Start();
pProcess.WaitForExit();
// Display returned console information if any
StreamReader srOut = pProcess.StandardOutput;
string sOutput = srOut.ReadToEnd();
srOut.Close();
pProcess.Close();
Why can't I hide the window anymore? Is there another way to do this? I really need to get the output from the process but I don't want it to appear on screen.
Any help would be greatly appreciated.
Thanks,