calling a program without waiting for it to finish
aleax at aleax.it
Thu Mar 20 17:47:28 CET 2003
>> Under Linux, appending an ampersand to the end of the command should
>> do roughly what you want, shouldn't it?
>> os.system("ping -blah -blah www.google.com &")
> Adding an ampersand seems to work fine. Can you tell me what exactly it
In all Unix shells I know (sh, bash, csh, zsh...), a trailing ampersand
after a pipeline (including the special case where the pipeline is a
single command, possibly with redirections) means the whole pipeline is
to be "run in the background", i.e.: even without the ampersand, the
shell always forks (N times for an N-stage pipeline) and execs the
various stages of the pipeline (after connecting their stdins/stdouts
via pipes) -- but, WITHOUT the ampersand, the shell also WAITS for the
whole caboodle to be finished -- WITH the ampersand, it does not wait,
but rather returns you to the shell prompt (well -- that's if you run
the shell interactively, only, of course!-) as soon as it's done
setting things up, so the pipeline runs in separate processes.
os.system delegates the whole operation to the system shell (normally
sh) so the above information should be directly applicable...
More information about the Python-list