return None
if isinstance(cmdln_or_args, list):
- args = cmdln_or_args
+ cmd = cmdln_or_args[0]
+ shell = False
else:
import shlex
- args = shlex.split(cmdln_or_args)
+ cmd = shlex.split(cmdln_or_args)[0]
+ shell = True
if catch != 3:
dev_null = os.open("/dev/null", os.O_WRONLY)
serr = PIPE
elif catch == 3:
sout = PIPE
- serr = PIPE
+ serr = STDOUT
try:
- p = Popen(args, stdout=sout, stderr=serr)
+ p = Popen(cmdln_or_args, stdout=sout, stderr=serr, shell=shell)
out = p.communicate()[0]
+ if out is None:
+ out = ''
except OSError, e:
if e.errno == 2:
# [Errno 2] No such file or directory
- msger.error('Cannot run command: %s, lost dependency?' % args[0])
+ msger.error('Cannot run command: %s, lost dependency?' % cmd)
else:
raise # relay
finally:
msger.verbose(msg)
return rc
-def outs(cmdln_or_args):
+def outs(cmdln_or_args, catch=1):
# get the outputs of tools
- return runtool(cmdln_or_args, catch=1)[1].strip()
+ return runtool(cmdln_or_args, catch)[1].strip()
def quiet(cmdln_or_args):
return runtool(cmdln_or_args, catch=0)[0]
-