[ python-Feature Requests-840034 ] additions to commands lib
SourceForge.net
noreply at sourceforge.net
Tue Nov 11 10:41:14 EST 2003
Feature Requests item #840034, was opened at 2003-11-11 09:41
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=840034&group_id=5470
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Mark Hattarki (mindfunk)
Assigned to: Nobody/Anonymous (nobody)
Summary: additions to commands lib
Initial Comment:
There currently is a function, commands.getstatusoutput. This, simply,
runs a command, returns it's exit code and and output. The problem
is, stderr and stdout are mixed. There are many real world examples
where this is not desirable. In fact, I've written the following function
in various forms many, many times:
def run_cmd(cmd):
pipe = popen2.Popen3(cmd, 1)
ret = pipe.wait()
return (ret, pipe.fromchild.readlines(-1),
pipe.childerr.readlines(-1))
This is a very simple command. Anyone could write it. But, I still think
is should be added because there is a function that is very similar to it
(getstatusoutput) that comes extremely close, but does something
that renders it useless if one wants to separate the two. It would be a
useful addition to the commands lib.
Also, I wouldn't nessesarily name it "run_cmd" if added to the lib.
I suppose one could have it throw exceptions as well:
def getouterr(cmd):
if not os.path.exists((cmd.split(' '))[0]):
raise ATSCommandPath(cmd, "command not found")
return run_cmd(cmd)
... obviously, one could do better error checking (searching $PATH,
etc). But, that is the basic point.
If you guys/gals will allow it, I would also like to submit the patch.
namaste,
Mark <mindfunk at mindfunk.net
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=840034&group_id=5470
More information about the Python-bugs-list
mailing list