I propose to add the the following convenience function:
os.run('some_program', infilename, '-o', outfilename)
as equivalent to
os.spawnvp(os.P_WAIT, 'some_program', ['some_program',
infilename, '-o', outfilename])
Rationale:
Newbies and more experienced programmers alike are
likely to make incorrect use of os.system for the
common task of running a process passing a couple of
arguments, when they should really be using os.spawnvp,
but the latter has an awkward interface and is much
more difficult to find in the docs (in a recent thread
[1]; a couple of regulars admitted either having been
bitten or at least finding os.spawnvp difficult to use
or awkward to remember).
As a consequence this (broken):
os.system('some_program %s -o %s' % (infilename,
outfilename)
is often used instead of
os.spawnvp(os.P_WAIT, 'some_program', ['some_program',
infilename, '-o', outfilename])
which works correctly, but is more awkward (and also
easy to get wrong, e.g. note the double occurence of
'some_program').
I propose to add the covenience function for the common
case (or at least some doc improvements) to make such
brittle code less common and especially to aid less
experienced programmers who are unlikely to even hit
upon os.spawnvp in the docs.
A similar function would also be useful for popen*
style use (which currently cannot be done at all
without shell-escaping by hand).
Further rationale and an implementation can be found in
[1].
[1] Message-ID: <yfs1xghfi38.fsf@black4.ex.ac.uk> or
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&c2coff=1&threadm=yfsacv24cdn.fsf%40black4.ex.ac.uk&rnum=1&prev=/groups%3Fq%3Dos.system%26hl%3Den%26lr%3D%26ie%3DUTF-8%26c2coff%3D1%26scoring%3Dd%26selm%3Dyfsacv24cdn.fsf%2540black4.ex.ac.uk%26rnum%3D1
|