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: additions to commands lib
Type: enhancement Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, mindfunk
Priority: normal Keywords:

Created on 2003-11-11 15:41 by mindfunk, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg54053 - (view) Author: Mark Hattarki (mindfunk) Date: 2003-11-11 15:41
 
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 
msg54054 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-05-13 07:55
You can/should use the subprocess module for this kind of process handling.
History
Date User Action Args
2022-04-11 14:56:01adminsetgithub: 39537
2003-11-11 15:41:14mindfunkcreate