Jump to content
Xtreme .Net Talk

Redirect Standard Output of a Process with window hidden? [C# 2002]


Recommended Posts

Posted

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.

 

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,

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...