subprocess.Popen spawning cmd shells

Discussion in 'Python' started by Mrown, Jan 9, 2008.

  1. Mrown

    Mrown Guest

    Hi,
    I'm currently writing a python program that relies on a CLI
    program. What I'm currently doing is using subprocess.Popen on Python
    2.5.1. Here's the line that I'm currently running:

    child = subprocess.Popen(["c:\app.exe", node, "-w",
    str(tmpTime * 1000), '-n', str(1), '-l'], stdin=subprocess.PIPE,
    stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    The problem is that although the above works, a CMD shell is spawned
    and becomes visible for each time I run the above. I thought that by
    redircting stdin, stdout and stderr, no CMD shell should pop-up. Is
    something wrong in the way I'm using subprocess? Thanks for your help.
     
    Mrown, Jan 9, 2008
    #1
    1. Advertisements

  2. Mrown

    Mrown Guest

    On Jan 9, 5:17 pm, Mrown <> wrote:
    > Hi,
    >   I'm currently writing a python program that relies on a CLI
    > program.  What I'm currently doing is using subprocess.Popen on Python
    > 2.5.1.  Here's the line that I'm currently running:
    >
    >             child = subprocess.Popen(["c:\app.exe", node, "-w",
    > str(tmpTime * 1000), '-n', str(1), '-l'], stdin=subprocess.PIPE,
    > stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    >
    > The problem is that although the above works, a CMD shell is spawned
    > and becomes visible for each time I run the above.  I thought that by
    > redircting stdin, stdout and stderr, no CMD shell should pop-up.  Is
    > something wrong in the way I'm using subprocess?  Thanks for your help.


    To anyone interested, I found the solution by using the
    CREATE_NO_WINDOW creation flag. So this is what the code now looks
    like (and it doesn't spawn any shells):

    CREATE_NO_WINDOW = 0x8000000
    child = subprocess.Popen(["c:\app.exe", node, "-w",
    str(tmpTime * 1000), '-n', str(1), '-l'], stdin=subprocess.PIPE,
    stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags =
    CREATE_NO_WINDOW)
     
    Mrown, Jan 9, 2008
    #2
    1. Advertisements

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. Achim Domma (Procoders)

    read input for cmd.Cmd from file

    Achim Domma (Procoders), Jun 3, 2005, in forum: Python
    Replies:
    2
    Views:
    8,351
    Peter Otten
    Jun 3, 2005
  2. Sarir Khamsi

    Interpreter-like help in cmd.Cmd

    Sarir Khamsi, Jun 9, 2005, in forum: Python
    Replies:
    4
    Views:
    559
    Bengt Richter
    Jun 26, 2005
  3. =?ISO-8859-1?Q?Sch=FCle_Daniel?=

    [exec cmd for cmd in cmds]

    =?ISO-8859-1?Q?Sch=FCle_Daniel?=, Mar 8, 2006, in forum: Python
    Replies:
    3
    Views:
    595
    Scott David Daniels
    Mar 8, 2006
  4. WolfgangZ

    subprocess.Popen(cmd) question

    WolfgangZ, Aug 10, 2007, in forum: Python
    Replies:
    1
    Views:
    455
    Peter Otten
    Aug 10, 2007
  5. bhunter
    Replies:
    14
    Views:
    694
    bhunter
    Nov 27, 2007
  6. Replies:
    0
    Views:
    2,063
  7. D
    Replies:
    3
    Views:
    1,496
    Gabriel Genellina
    Oct 18, 2009
  8. Ross Boylan

    question about subprocess and shells

    Ross Boylan, Dec 4, 2009, in forum: Python
    Replies:
    3
    Views:
    429
    Nobody
    Dec 5, 2009
Loading...