Mercurial > treepkg > treepkg
diff treepkg/run.py @ 451:eacfd3744d16
capture only stdout for treepkginfo
author | Bjoern Ricks <bricks@intevation.de> |
---|---|
date | Fri, 13 Aug 2010 14:16:50 +0000 |
parents | 2910051b91f7 |
children |
line wrap: on
line diff
--- a/treepkg/run.py Wed Aug 11 07:45:26 2010 +0000 +++ b/treepkg/run.py Fri Aug 13 14:16:50 2010 +0000 @@ -67,3 +67,17 @@ if proc.returncode != 0: raise SubprocessError(command, proc.returncode, output) return output + +def capture_stdout(command, **kw): + """Return the stdout and stderr of the command as a string + + The command should be given as a list of strings to avoid problems + with shell quoting. If the command exits with a return code other + than 0, a SubprocessError is raised. + """ + proc = subprocess.Popen(command, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, **kw) + output, error = proc.communicate() + if proc.returncode != 0: + raise SubprocessError(command, proc.returncode, error) + return output