os.system question
Donn Cave
donn at oz.net
Fri Apr 13 01:30:32 EDT 2001
Quoth Thomas Duterme <thomas at madeforchina.com>:
| This may sound silly, but I have a question on os.system().
|
| Let's say I have a script while calls some program XXX via
| os.system(). Will python wait for XXX to finish what its
Yes.
| ... but what if I wanted
| python to just mosey on down while launching a
| subprocess...(ie not wait) How would this be done?
Where you're invoking another program, you can use the os.spawnv()
function or one of its relatives in both cases.
>>> print os.spawnv.__doc__
spawnv(mode, file, args) -> integer
Execute file with arguments from args in a subprocess.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it.
That's better not only because you can get what you're asking
for, but also because the value of args is passed directly to
the program instead of having to be interpreted by a shell, as
in os.system(). That interpretation step is not so terribly
expensive, but it's vulnerable to terrible errors if the data
may contain shell metacharacters.
Donn Cave, donn at oz.net
More information about the Python-list
mailing list