473,413 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

windows background process

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
4 4077
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
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Michael Riggio | last post by:
Is there a way to have a windows service instantiate a class that is a web service, which will then be accessible to clients via HTTP? Thanks, -Mike
3
by: Michael | last post by:
Hi, I have a windows service developed using c# and it needs to lunch another windows application. I have been trying to use Process class to do it but the problem is becase windows service...
3
by: belgiozen | last post by:
Hi, I have a working windows service,it is looking for files on the disk and when some of the files are cupdated it calls an executable. But it takes a lot of time(about 10 minutes) to run the...
7
by: Mullin Yu | last post by:
if i put the same code at the windows application or console, i can logon to the computer. but, if i put the same code at the windows service and start it, i still can't logon to the machine. ...
4
by: Primo | last post by:
Hi, This problem has been frustrating me for days and I hope you experts can help me out. I am trying to run a command, which I would normally run from the command line, from within my C#...
14
by: | last post by:
Hi All, I am little confused here, hope you can help me. While processing WM_POWERBROADCAST (wParam=PBT_APMQUERYSUSPEND), I MUST to do some lengthy operation(30 sec) before system Suspends or...
2
by: Larry | last post by:
Hello I see that Windows Services are suppose to be able to run in their own background process. I can create simple Services based on the MSDN walkthrough, and get the OnStart/OnStop methods to...
1
by: PankajLohani | last post by:
hello, This is very challenging problem for me. basically my windows service monitor the application when my application hang due any reason then my service kill that process and application .Then...
20
by: Alexey Kulentsov | last post by:
Hi all! Windows XP, Apache 2.2, PHP 5.2.5 as apache module (php5apache2_2.dll) I need to run background process and see output but for current moment all methods runs it as process not as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.