By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

windows background process

P: n/a
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
>>os.popen("mycmd.exe myargs") # works
if __name__ == '__main__':
os.popen("mycmd.exe myargs") # hangs

2.
>>os.system("mycmd.exe myargs") # hangs, as expected
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')

Nov 23 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

Nov 23 '06 #2

P: n/a
At Wednesday 22/11/2006 21:27, Podi wrote:
>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
Nov 25 '06 #3

P: n/a
At Wednesday 22/11/2006 22:05, Podi wrote:
>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
Nov 25 '06 #4

P: n/a

Gabriel Genellina wrote:
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

Nov 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.