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

execute commands independantly

P: n/a
Hi,

I am trying to execute an executable or a pyton script inside my
program. I looked at the subprocess and os module. But all the
functions in these modules blocks my application. What I want to do is
run the subprocess without any concern. I don't care of its return type
or child signals. Just start and let it run independantly.

Thanks,
Mike

Sep 6 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Mike Tammerman wrote:
Hi,

I am trying to execute an executable or a pyton script inside my
program. I looked at the subprocess and os module. But all the
functions in these modules blocks my application.


subprocess doesn't block unless you call .wait():

from subprocess import Popen
proc = Popen('sleep 2; echo "Hello, world!"', shell=True)
print "In two seconds, something will happen."
proc.wait()
print "Did you see that?"
Sep 6 '05 #2

P: n/a

Mike Tammerman wrote:
I am trying to execute an executable or a pyton script inside my
program. I looked at the subprocess and os module. But all the
functions in these modules blocks my application. What I want to do is
run the subprocess without any concern. I don't care of its return type
or child signals. Just start and let it run independantly.


If you don't need any output, os.system('app') should do.

Sep 6 '05 #3

P: n/a

If you want it to return when the program is finished then use
os.system('app') but if you just want to start it and return right
away, use os.startfile('app')

Sep 6 '05 #4

P: n/a
You're right,

I tried subprocess.call and os.spawn* functions. Popen is what I will
be happy with.

Thanks a lot.

Mike

Sep 6 '05 #5

P: n/a
On 6 Sep 2005 08:07:12 -0700, Eric McGraw <th************@gmail.com> wrote:

If you want it to return when the program is finished then use
os.system('app') but if you just want to start it and return right
away, use os.startfile('app')


That one is Windows-only, though -- at least in 2.3 where I live. The
os.spawn* family of calls are more portable, but I'm not sure it's a good
idea to just spawn-and-forget a process.

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
Sep 6 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.