Win XP: How to hide command window for sub processes?

Discussion in 'Python' started by klausfpga, Oct 29, 2009.

  1. klausfpga

    klausfpga Guest

    Hi,

    I have a Python script which wants to start a subprocess and wait for
    it to finish.

    However I would like to have NO command window popping up during
    execution.

    My main Python script is started with the .pyw suffix, thus I got rid
    of the main console and I just see my GUI.

    So far I tried
    os.system()

    and subprocess.call()

    with os.system() the command window pops up and I see my commands
    output.

    with the subprocess.call() and stdin ./ stdout / stderr redirection I
    manage to get rid of stdout/stderr
    ( redirecting to the file 'NUL:' )

    but the window stays.

    the subprocess is a call to a .exe file with multiple parameters.

    I would appreciate any hints


    bye


    Klaus
     
    klausfpga, Oct 29, 2009
    #1
    1. Advertising

  2. klausfpga schrieb:
    > Hi,
    >
    > I have a Python script which wants to start a subprocess and wait for
    > it to finish.
    >
    > However I would like to have NO command window popping up during
    > execution.


    You need to specify the hide parameter for windows.

    import subprocess
    kwargs = {}
    if subprocess.mswindows:
    su = subprocess.STARTUPINFO()
    su.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    su.wShowWindow = subprocess.SW_HIDE
    kwargs['startupinfo'] = su
    process = subprocess.Popen( (r'c:\python25\python.exe',
    r'd:\projekte\bar.py'), **kwargs )
     
    Rüdiger Ranft, Oct 29, 2009
    #2
    1. Advertising

  3. klausfpga

    Chris Rebert Guest

    Re: Win XP: How to hide command window for sub processes?

    On Thu, Oct 29, 2009 at 3:25 AM, Rüdiger Ranft <> wrote:
    > klausfpga schrieb:
    >> Hi,
    >>
    >> I have a Python script which wants to start a subprocess and wait for
    >> it to finish.
    >>
    >> However I would like to have NO command window popping up during
    >> execution.

    >
    > You need to specify the hide parameter for windows.
    >
    > import subprocess
    > kwargs = {}
    > if subprocess.mswindows:
    >    su = subprocess.STARTUPINFO()
    >    su.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    >    su.wShowWindow = subprocess.SW_HIDE
    >    kwargs['startupinfo'] = su
    > process = subprocess.Popen( (r'c:\python25\python.exe',
    >    r'd:\projekte\bar.py'), **kwargs )


    Interestingly, none of that appears to be documented. I smell a docs
    bug waiting to be reported.

    Cheers,
    Chris
    --
    http://blog.rebertia.com
     
    Chris Rebert, Oct 29, 2009
    #3
  4. Re: Win XP: How to hide command window for sub processes?

    Chris Rebert wrote:
    > On Thu, Oct 29, 2009 at 3:25 AM, Rüdiger Ranft <> wrote:
    >> klausfpga schrieb:
    >>> Hi,
    >>>
    >>> I have a Python script which wants to start a subprocess and wait for
    >>> it to finish.
    >>>
    >>> However I would like to have NO command window popping up during
    >>> execution.

    >> You need to specify the hide parameter for windows.
    >>
    >> import subprocess
    >> kwargs = {}
    >> if subprocess.mswindows:
    >> su = subprocess.STARTUPINFO()
    >> su.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    >> su.wShowWindow = subprocess.SW_HIDE
    >> kwargs['startupinfo'] = su
    >> process = subprocess.Popen( (r'c:\python25\python.exe',
    >> r'd:\projekte\bar.py'), **kwargs )

    >
    > Interestingly, none of that appears to be documented.


    Except for here:
    http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx

    > I smell a docs bug waiting to be reported.
    >
    > Cheers,
    > Chris
    > --
    > http://blog.rebertia.com


    --
    MPH
    http://blog.dcuktec.com
    'If consumed, best digested with added seasoning to own preference.'
     
    Martin P. Hellwig, Oct 29, 2009
    #4
  5. klausfpga

    Chris Rebert Guest

    Re: Win XP: How to hide command window for sub processes?

    On Thu, Oct 29, 2009 at 4:37 AM, Martin P. Hellwig
    <> wrote:
    > Chris Rebert wrote:
    >>
    >> On Thu, Oct 29, 2009 at 3:25 AM, Rüdiger Ranft <> wrote:
    >>>
    >>> klausfpga schrieb:
    >>>>
    >>>> Hi,
    >>>>
    >>>> I have a Python script which wants to start a subprocess and wait for
    >>>> it to finish.
    >>>>
    >>>> However I would like to have NO command window popping up during
    >>>> execution.
    >>>
    >>> You need to specify the hide parameter for windows.
    >>>
    >>> import subprocess
    >>> kwargs = {}
    >>> if subprocess.mswindows:
    >>>   su = subprocess.STARTUPINFO()
    >>>   su.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    >>>   su.wShowWindow = subprocess.SW_HIDE
    >>>   kwargs['startupinfo'] = su
    >>> process = subprocess.Popen( (r'c:\python25\python.exe',
    >>>   r'd:\projekte\bar.py'), **kwargs )

    >>
    >> Interestingly, none of that appears to be documented.

    >
    > Except for here:
    > http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx


    I was referring to the following bits of the subprocess module used in
    the above code:
    subprocess.mswindows
    subprocess.STARTUPINFO()
    subprocess.STARTF_USESHOWWINDOW
    subprocess.SW_HIDE

    none of which are mentioned in the module's docs:
    http://docs.python.org/dev/py3k/library/subprocess.html

    Cheers,
    Chris
    --
    http://blog.rebertia.com
     
    Chris Rebert, Oct 29, 2009
    #5
  6. Re: Win XP: How to hide command window for sub processes?

    Chris Rebert wrote:
    <cut>
    >> Except for here:
    >> http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx

    >
    > I was referring to the following bits of the subprocess module used in
    > the above code:


    Me too actually :)

    > subprocess.mswindows
    > subprocess.STARTUPINFO()
    > subprocess.STARTF_USESHOWWINDOW
    > subprocess.SW_HIDE
    >
    > none of which are mentioned in the module's docs:
    > http://docs.python.org/dev/py3k/library/subprocess.html


    Since this is platform specific stuff I would argue that it has no
    business being repeated, although a link to where it is documented
    elsewhere would have been nice.

    --
    MPH
    http://blog.dcuktec.com
    'If consumed, best digested with added seasoning to own preference.'
     
    Martin P. Hellwig, Oct 29, 2009
    #6
  7. klausfpga

    Chris Rebert Guest

    Re: Win XP: How to hide command window for sub processes?

    On Thu, Oct 29, 2009 at 4:57 AM, Martin P. Hellwig
    <> wrote:
    > Chris Rebert wrote:
    > <cut>
    >>>
    >>> Except for here:
    >>> http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx

    >>
    >> I was referring to the following bits of the subprocess module used in
    >> the above code:

    >
    > Me too actually :)
    >
    >> subprocess.mswindows
    >> subprocess.STARTUPINFO()
    >> subprocess.STARTF_USESHOWWINDOW
    >> subprocess.SW_HIDE
    >>
    >> none of which are mentioned in the module's docs:
    >> http://docs.python.org/dev/py3k/library/subprocess.html

    >
    > Since this is platform specific stuff I would argue that it has no business
    > being repeated, although a link to where it is documented elsewhere would
    > have been nice.


    True, the Windows APIs are documented but it's not mentioned at all
    that they're accessible in a certain form from subprocess.
    Many other stdlib modules (e.g. `os` -
    http://docs.python.org/library/os.html) include and list
    platform-specific functions, I don't see why subprocess should be
    different.

    Cheers,
    Chris
    --
    http://blog.rebertia.com
     
    Chris Rebert, Oct 29, 2009
    #7
  8. klausfpga

    klausfpga Guest

    Re: Win XP: How to hide command window for sub processes?

    On Oct 29, 11:25 am, Rüdiger Ranft <> wrote:
    > klausfpga schrieb:
    >
    > > Hi,

    >
    > > I have a Python script which wants to start a subprocess and wait for
    > > it to finish.

    >
    > > However I would like to have NO command window popping up during
    > > execution.

    >
    > You need to specify the hide parameter for windows.
    >
    > import subprocess
    > kwargs = {}
    > if subprocess.mswindows:
    >     su = subprocess.STARTUPINFO()
    >     su.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    >     su.wShowWindow = subprocess.SW_HIDE
    >     kwargs['startupinfo'] = su
    > process = subprocess.Popen( (r'c:\python25\python.exe',
    >     r'd:\projekte\bar.py'), **kwargs )


    Thanks Ruediger,

    I'll try that immediately tomorrow, when working again on a windows
    host.

    Good to know, that the Python API supports this.
    though this feature was not that easy to be found in the doc.

    This will make my application much nicer.
     
    klausfpga, Oct 29, 2009
    #8
  9. Re: Win XP: How to hide command window for sub processes?

    klausfpga schrieb:
    > On Oct 29, 11:25 am, Rüdiger Ranft <> wrote:


    > Thanks Ruediger,
    >
    > I'll try that immediately tomorrow, when working again on a windows
    > host.
    >
    > Good to know, that the Python API supports this.
    > though this feature was not that easy to be found in the doc.


    Well, getting the point from subproces.py was easy. Finding the
    documentation about STARTUPINFO in the MSDN was not. I better stop here
    before this post turns into a rant about Mircosofts use of javascript.

    bye
    Rudi
     
    Rüdiger Ranft, Nov 4, 2009
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Rodriguez
    Replies:
    23
    Views:
    1,210
    David Schwartz
    Dec 9, 2003
  2. Ben
    Replies:
    2
    Views:
    963
  3. Krist
    Replies:
    6
    Views:
    805
    Arne Vajhøj
    May 7, 2010
  4. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    2,177
    Lawrence D'Oliveiro
    May 20, 2011
  5. Marc Heiler
    Replies:
    1
    Views:
    192
    Robert Klemme
    May 24, 2009
Loading...

Share This Page