windows background process

P

Podi

Hi,

I am using Python 2.4.4 on Windows XP SP2.

I am trying to start a process (infinite loop application) in the
background and I've tried several options and none of them seem to
work.

Any help would be much appreciated.

Thanks,
P

1.
# This works on PythonWin interactive window, but the python.exe
process hangs until mycmd.exe process dies
if __name__ == '__main__':
os.popen("mycmd.exe myargs") # hangs

2.

3.
os.spawnl(os.P_NOWAIT, 'mycmd.exe', 'myargs') # mycmd.exe not started
os.spawnv(os.P_NOWAIT, 'mycmd.exe', tuple('myargs')) # mycmd.exe not
started

4.
# Works, but not portable. My code is expected to run on *nix later on
os.system('start /B "dummy title" "mycmd.exe" myargs')
 
P

Podi

Some update...

I just found out that the following seems to work,

import subprocess
subprocess.Popen(' myargs', executable='mycmd.exe')

However, it does not work with "my path\\mycmd.exe"

subprocess.Popen(' myargs', executable='"my path\\mycmd.exe"') # error
 
G

Gabriel Genellina

3.
os.spawnl(os.P_NOWAIT, 'mycmd.exe', 'myargs') # mycmd.exe not started
os.spawnv(os.P_NOWAIT, 'mycmd.exe', tuple('myargs')) # mycmd.exe not
started

os.spawnl(os.P_NOWAIT, 'mycmd.exe', 'mycmd.exe', 'first_arg', 'second_arg')
That is, you must provide explicitely the value for argv[0] (executable)
Remember to quote appropiately any parameter with embedded spaces
(including the executable). On Python 2.5 you could use subprocess.list2cmdline


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 
G

Gabriel Genellina

Some update...

I just found out that the following seems to work,

import subprocess
subprocess.Popen(' myargs', executable='mycmd.exe')

However, it does not work with "my path\\mycmd.exe"

subprocess.Popen(' myargs', executable='"my path\\mycmd.exe"') # error

Same as before, executable should be the first argument, so it's seldom used.
Try subprocess.Popen((full_path_to_mycmd, full_path_to_mycmd, arg1, arg2))


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 
P

Podi

Gabriel said:
os.spawnl(os.P_NOWAIT, 'mycmd.exe', 'mycmd.exe', 'first_arg', 'second_arg')
That is, you must provide explicitely the value for argv[0] (executable)
Remember to quote appropiately any parameter with embedded spaces
(including the executable). On Python 2.5 you could use subprocess.list2cmdline
Right, this works. Before, I didn't realize that the full path goes to
the 2nd and 3rd argument of spawnl.

Thanks for the help.
P
 

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

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top