FAQ
Hello all,

What I want to do: launch seperate python programs from one main
program (multi-threading will not achieve this because the mechanize
library uses one shared global opener object which will not suit my
needs) I want the scripts launched to be in seperate windows that i
can see the output of on screen, seperate processes. I can accomplish
this in win32 by:

import subprocess;
args = ["cmd", "/c", "START", "python", "myScript.py"];
process1 = subprocess.Popen(args, shell=False);

however, doing will open a new window, but will lose the process id:

e.g. process1.poll() will always return 0 no matter if the process is
open or not, meaning that python always thinks its closed.
It should return None if the process is still running.

I can do it without using cmd /c start, but then the newly launched
python script is trapped in my original cmd terminal where i launched
the script from in the first place. I can keep track of the process
now, but the one cmd window open is insufficient to keep track of the
output that a multitude of programs running will produce. Doing it
without the /c argument will still keep the new script in the same
console.

Yes, I have read I can do this in linux with Konsole or whatever like:
child = subprocess.Popen("konsole -e python foo.py", shell=True)

however, I need this to run in windows.


Any help or solution is appreciated,


--
Zak Kinion
zkinion at gmail.com

Search Discussions

  • Tim Golden at Nov 3, 2010 at 2:48 pm

    On 02/11/2010 20:55, Zak Kinion wrote:
    What I want to do: launch seperate python programs from one main
    program (multi-threading will not achieve this because the mechanize
    library uses one shared global opener object which will not suit my
    needs) I want the scripts launched to be in seperate windows that i
    can see the output of on screen, seperate processes. I can accomplish
    this in win32 by:

    import subprocess;
    args = ["cmd", "/c", "START", "python", "myScript.py"];
    process1 = subprocess.Popen(args, shell=False);
    Pass CREATE_NEW_CONSOLE as one of the creationflags:

    <code>
    import os, sys
    import subprocess

    processes = []
    cmd = [sys.executable, "-c", "import os; print os.getpid (); raw_input ()"]
    for i in range (3):
    processes.append (subprocess.Popen (cmd,
    creationflags=subprocess.CREATE_NEW_CONSOLE))

    #
    # Keep looping round to see the current status
    #
    while True:
    for p in processes:
    print p.poll ()

    raw_input ()

    </code>

    TJG

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 2, '10 at 8:55p
activeNov 3, '10 at 2:48p
posts2
users2
websitepython.org

2 users in discussion

Tim Golden: 1 post Zak Kinion: 1 post

People

Translate

site design / logo © 2022 Grokbase