Kick off a delete command from python and not wait

Chris Rebert clp2 at rebertia.com
Tue Jul 20 13:32:12 EDT 2010


On Tue, Jul 20, 2010 at 8:33 AM, loial <jldunn2000 at gmail.com> wrote:
> I have a requirement to kick off a shell script from a python script
> without waiting for it to complete. I am not bothered about any return
> code from the script.
>
> What is the easiest way to do this. I have looked at popen but cannot
> see how to do it.

Use the `subprocess` module.

import subprocess
proc = subprocess.Popen(["shell_script.sh", "arg1", "arg2"],
stdout=subprocess.PIPE, stderr=subprcoess.PIPE)
# lots of code here doing other stuff
proc.wait()

I believe you need to /eventually/ call .wait() as shown to avoid the
child becoming a zombie process.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list