[csw-devel] SF.net SVN: gar:[20986] csw/mgar/gar/v2/lib/python/shell.py

chninkel at users.sourceforge.net chninkel at users.sourceforge.net
Sat May 4 13:11:11 CEST 2013


Revision: 20986
          http://gar.svn.sourceforge.net/gar/?rev=20986&view=rev
Author:   chninkel
Date:     2013-05-04 11:11:10 +0000 (Sat, 04 May 2013)
Log Message:
-----------
ShellCommand should always return the same number of values

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/shell.py

Modified: csw/mgar/gar/v2/lib/python/shell.py
===================================================================
--- csw/mgar/gar/v2/lib/python/shell.py	2013-05-04 10:49:55 UTC (rev 20985)
+++ csw/mgar/gar/v2/lib/python/shell.py	2013-05-04 11:11:10 UTC (rev 20986)
@@ -20,6 +20,11 @@
                  stdout=subprocess.PIPE,
                  stderr=subprocess.PIPE):
   logging.debug("Running: %s", args)
+
+  if not quiet:
+    stdout = subprocess.STDOUT
+    stderr = subprocess.STDOUT
+
   # Python 3.3 have the timeout option
   # we have to roughly emulate it with python 2.x
   if timeout:
@@ -27,21 +32,17 @@
     signal.alarm(timeout)
 
   try:
-    if not quiet:
-      retcode = subprocess.call(args)
+    proc = subprocess.Popen(args,
+                            stdout=stdout,
+                            stderr=stderr,
+                            env=env,
+                            preexec_fn=os.setsid,
+                            close_fds=True)
+    stdout, stderr = proc.communicate()
+    retcode = proc.wait()
 
-    else:
-      proc = subprocess.Popen(args,
-                              stdout=stdout,
-                              stderr=stderr,
-                              env=env,
-                              preexec_fn=os.setsid,
-                              close_fds=True)
-      stdout, stderr = proc.communicate()
-      retcode = proc.wait()
-
     signal.alarm(0)
-      
+
   except TimeoutExpired:
     os.kill(-proc.pid, signal.SIGKILL)
     msg = "Process %s killed after timeout expiration" % args
@@ -52,8 +53,4 @@
     logging.critical(stderr)
     raise Error("Running %s has failed." % repr(args))
 
-  if quiet:
-    return retcode, stdout, stderr
-  else:
-    return retcode
-
+  return retcode, stdout, stderr

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list