From adf23456e598060c226a185fe3f191668e6fd3f1 2013-07-30 04:07:10 From: Paul Ivanov Date: 2013-07-30 04:07:10 Subject: [PATCH] new util that also passes back the returncode --- diff --git a/IPython/utils/_process_common.py b/IPython/utils/_process_common.py index 34ca83b..926721c 100644 --- a/IPython/utils/_process_common.py +++ b/IPython/utils/_process_common.py @@ -139,13 +139,31 @@ def getoutputerror(cmd): stdout : str stderr : str """ + return get_output_error_code(cmd)[:2] - out_err = process_handler(cmd, lambda p: p.communicate()) +def get_output_error_code(cmd): + """Return (standard output, standard error, return code) of executing cmd + in a shell. + + Accepts the same arguments as os.system(). + + Parameters + ---------- + cmd : str + A command to be executed in the system shell. + + Returns + ------- + stdout : str + stderr : str + returncode: int + """ + + out_err, p = process_handler(cmd, lambda p: (p.communicate(), p)) if out_err is None: - return '', '' + return '', '', p.returncode out, err = out_err - return py3compat.bytes_to_str(out), py3compat.bytes_to_str(err) - + return py3compat.bytes_to_str(out), py3compat.bytes_to_str(err), p.returncode def arg_split(s, posix=False, strict=True): """Split a command line's arguments in a shell-like manner. diff --git a/IPython/utils/process.py b/IPython/utils/process.py index 42c6bf5..b7f71c4 100644 --- a/IPython/utils/process.py +++ b/IPython/utils/process.py @@ -27,7 +27,7 @@ else: from ._process_posix import _find_cmd, system, getoutput, arg_split -from ._process_common import getoutputerror +from ._process_common import getoutputerror, get_output_error_code #----------------------------------------------------------------------------- # Code