runner.py: fixed several issues
authorJF Ding <jian-feng.ding@intel.com>
Mon, 13 Feb 2012 07:19:40 +0000 (15:19 +0800)
committerJF Ding <jian-feng.ding@intel.com>
Mon, 13 Feb 2012 07:19:40 +0000 (15:19 +0800)
sync the changes from gbs project

mic/utils/runner.py

index 8952e7c..12fa930 100644 (file)
@@ -38,10 +38,12 @@ def runtool(cmdln_or_args, catch=1):
         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)
@@ -57,15 +59,17 @@ def runtool(cmdln_or_args, catch=1):
         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:
@@ -96,10 +100,9 @@ def show(cmdln_or_args):
     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]
-