subprocess terminate help

E

Ernesto

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?
 
F

Fredrik Lundh

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>
 
E

Ernesto

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.
 
F

Fredrik Lundh

Ernesto said:
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>
 
E

Ernesto

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!
 
D

Do Re Mi chel La Si Do

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
 
E

Ernesto

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.
 
F

Fredrik Lundh

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top