Results 1 to 4 of 4

Thread: [1.0/1.1] Redirect Standard Output of a Process with window hidden? [C# 2002]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308

    Question [1.0/1.1] Redirect Standard Output of a Process with window hidden? [C# 2002]

    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.

    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,

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [1.0/1.1] Redirect Standard Output of a Process with window hidden? [C# 2002]

    I see what you mean. You need UserShellExecute = False in order for RedirectStandardOutput = True. But you can't seem to hide the window with UserShellExecute = False. Interesting.

    I don't know if this will even help at all, but perhaps you'll find some ideas here. Or perphaps there is some sort of API that will help you if this doesn't?
    http://vbforums.com/showthread.php?t...t=redirect+cmd

    Good luck.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308

    Re: [1.0/1.1] Redirect Standard Output of a Process with window hidden? [C# 2002]

    I think I figured it out actually - oddly enough:
    Code:
    pProcess.StartInfo.CreateNoWindow = true;
    That seems to do the trick - unless someone can tell me why that is a bad thing to do...

  4. #4
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [1.0/1.1] Redirect Standard Output of a Process with window hidden? [C# 2002]

    Quote Originally Posted by Shaitan00
    I think I figured it out actually - oddly enough:
    Code:
    pProcess.StartInfo.CreateNoWindow = true;
    That seems to do the trick - unless someone can tell me why that is a bad thing to do...
    Don't see why. That was what was in the post I linked to. Glad you got it figured out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width