subprocess terminate help

Discussion in 'Python' started by Ernesto, Nov 16, 2005.

  1. Ernesto

    Ernesto Guest

    def launchWithoutConsole(command, args):
    """Launches 'command' windowless and waits until finished"""
    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    return subprocess.Popen([command] + args,
    startupinfo=startupinfo).wait()


    handle = launchWithoutConsole("program.exe",["disconnect"])
    ------------------------------------------------------------------------------------------------------------------------------

    I've been searching for ways to terminate this process so I can exit my
    program. program.exe is a text based interface which I'm running with
    python subprocess in a DOS command window. I tried using 'sys.exit()'
    to end my program, but nothing works. I think I have to somehow
    terminate the subprocesses I create. Any suggestions?
    Ernesto, Nov 16, 2005
    #1
    1. Advertising

  2. Ernesto wrote

    > I've been searching for ways to terminate this process so I can exit my
    > program. program.exe is a text based interface which I'm running with
    > python subprocess in a DOS command window. I tried using 'sys.exit()'
    > to end my program, but nothing works. I think I have to somehow
    > terminate the subprocesses I create. Any suggestions?


    someone calling himself "Ernesto" posted this link yesterday:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347462

    </F>
    Fredrik Lundh, Nov 16, 2005
    #2
    1. Advertising

  3. Ernesto

    Ernesto Guest

    Yeah I know. I posted it b/c I was having the same problems and I'm
    investigating ways to do this. None of those methods gave me desired
    results for my program. All I want to do is end my python program and
    return to the DOS prompt.
    Ernesto, Nov 16, 2005
    #3
  4. Ernesto wrote:

    > Yeah I know. I posted it b/c I was having the same problems and I'm
    > investigating ways to do this. None of those methods gave me desired
    > results for my program. All I want to do is end my python program and
    > return to the DOS prompt.


    what about the other program? do you want to terminate that as well ?

    </F>
    Fredrik Lundh, Nov 16, 2005
    #4
  5. Ernesto

    Ernesto Guest

    Ahhhh... I figured out a way around this. I'll use program.exe to shut
    down itself. That way I won't have to use any extension modules.

    Thanks!
    Ernesto, Nov 16, 2005
    #5
  6. Hi!

    Self-destruction of a script:

    import os
    os.popen('TASKKILL /PID '+str(os.getpid())+' /F')

    (only in windows XP or 2K)


    @-salutations

    Michel Claveau
    Do Re Mi chel La Si Do, Nov 16, 2005
    #6
  7. Ernesto

    Ernesto Guest

    program.exe ? I was looking at the Windows task manager after I used a
    Cntrl + C to manually terminate the running python program. The
    program.exe is apparently ending when I end the python program.
    Ernesto, Nov 16, 2005
    #7
  8. Ernesto wrote

    > program.exe ? I was looking at the Windows task manager after I used a
    > Cntrl + C to manually terminate the running python program. The
    > program.exe is apparently ending when I end the python program.


    I have to admit that I have no idea what you're doing, really. The code
    you used *explicitly* waits for the "program.exe" program to finish. If
    you don't want that, why are you telling the subprocess module to wait?
    If you do want it to wait, why are you killing the python process ?

    </F>
    Fredrik Lundh, Nov 16, 2005
    #8
    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. Peter
    Replies:
    0
    Views:
    513
    Peter
    Aug 28, 2004
  2. Denon
    Replies:
    1
    Views:
    2,049
  3. Denon
    Replies:
    0
    Views:
    386
    Denon
    Nov 14, 2003
  4. Jackyms0083

    Why /0 can't terminate string? please help

    Jackyms0083, Sep 30, 2006, in forum: C Programming
    Replies:
    1
    Views:
    1,692
    Mash_online
    Nov 14, 2006
  5. hiral
    Replies:
    2
    Views:
    599
    Jean-Michel Pichavant
    May 5, 2010
Loading...

Share This Page