From be723aa98b43ba24b986cbe2b967082ba5d68dbb Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 14 Mar 2012 20:40:06 -0400 Subject: [PATCH] 'shell' is a magic module that executes the command module with shell=True --- command | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/command b/command index 06f5d656363..90b6b09d7db 100755 --- a/command +++ b/command @@ -32,18 +32,27 @@ import os argfile = sys.argv[1] args = open(argfile, 'r').read() -args = shlex.split(args) + +shell = False + +if args.find("#USE_SHELL") != -1: + args = args.replace("#USE_SHELL", "") + shell = True + +if not shell: + args = shlex.split(args) startd = datetime.datetime.now() try: - cmd = subprocess.Popen(args, shell=False, + cmd = subprocess.Popen(args, shell=shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = cmd.communicate() except (OSError, IOError), e: print json.dumps({ - "failed": 1, - "msg": str(e), + "cmd" : args, + "failed" : 1, + "msg" : str(e), }) sys.exit(1) except: @@ -62,6 +71,7 @@ if err is None: err = '' result = { + "cmd" : args, "stdout" : out.strip(), "stderr" : err.strip(), "rc" : cmd.returncode,