[ python-Feature Requests-1040267 ] os.run function for convinience and robustness

SourceForge.net noreply at sourceforge.net
Tue Nov 16 21:07:49 CET 2004


Feature Requests item #1040267, was opened at 2004-10-05 01:00
Message generated for change (Comment added) made by astrand
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1040267&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Alexander Schmolck (aschmolck)
Assigned to: Nobody/Anonymous (nobody)
Summary: os.run function for convinience and robustness

Initial Comment:
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 at 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

----------------------------------------------------------------------

>Comment By: Peter Åstrand (astrand)
Date: 2004-11-16 21:07

Message:
Logged In: YES 
user_id=344921

I think this is solved by subprocess.call(). 

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1040267&group_id=5470


More information about the Python-bugs-list mailing list