From 20520c17d65614da1e1316fc857eccd0fc541aee Mon Sep 17 00:00:00 2001 From: Travis Shirk Date: Thu, 26 Nov 2015 18:57:53 -0700 Subject: [PATCH] Support 3-tuple alias retval to include return code. --- xonsh/proc.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xonsh/proc.py b/xonsh/proc.py index 1201b85da..f777d12f0 100644 --- a/xonsh/proc.py +++ b/xonsh/proc.py @@ -16,8 +16,8 @@ from threading import Thread from collections import Sequence from subprocess import Popen, PIPE, DEVNULL, STDOUT, TimeoutExpired -from xonsh.tools import redirect_stdout, redirect_stderr, ON_WINDOWS, ON_LINUX, \ - fallback, print_exception +from xonsh.tools import (redirect_stdout, redirect_stderr, ON_WINDOWS, ON_LINUX, + fallback, print_exception) if ON_LINUX: from xonsh.teepty import TeePTY @@ -336,6 +336,8 @@ class SimpleProcProxy(ProcProxy): i = stdin.read() with redirect_stdout(stdout), redirect_stderr(stderr): r = f(args, i) + + cmd_result = 0 if isinstance(r, str): stdout.write(r) elif isinstance(r, Sequence): @@ -343,9 +345,11 @@ class SimpleProcProxy(ProcProxy): stdout.write(r[0]) if r[1] is not None: stderr.write(r[1]) + if len(r) > 2 and r[2] is not None: + cmd_result = r[2] elif r is not None: stdout.write(str(r)) - return 0 # returncode for succees + return cmd_result except Exception: print_exception() return 1 # returncode for failure