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@mindfunk.net
|