This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.run function for convinience and robustness
Type: enhancement Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: aschmolck, astrand, jlgijsbers
Priority: normal Keywords:

Created on 2004-10-04 23:00 by aschmolck, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg54275 - (view) Author: Alexander Schmolck (aschmolck) Date: 2004-10-04 23:00
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
msg54276 - (view) Author: Peter Åstrand (astrand) * (Python committer) Date: 2004-11-16 20:07
Logged In: YES 
user_id=344921

I think this is solved by subprocess.call(). 
msg54277 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-11-16 20:25
Logged In: YES 
user_id=469548

So it has. Closing.
History
Date User Action Args
2022-04-11 14:56:07adminsetgithub: 40983
2004-10-04 23:00:25aschmolckcreate