[ python-Feature Requests-840034 ] additions to commands lib
SourceForge.net
noreply at sourceforge.net
Sun May 13 09:55:35 CEST 2007
Feature Requests item #840034, was opened at 2003-11-11 15:41
Message generated for change (Comment added) made by gbrandl
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=840034&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
>Status: Closed
>Resolution: Rejected
Priority: 5
Private: No
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
----------------------------------------------------------------------
>Comment By: Georg Brandl (gbrandl)
Date: 2007-05-13 07:55
Message:
Logged In: YES
user_id=849994
Originator: NO
You can/should use the subprocess module for this kind of process
handling.
----------------------------------------------------------------------
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