Index: build/android/pylib/cmd_helper.py |
diff --git a/build/android/pylib/cmd_helper.py b/build/android/pylib/cmd_helper.py |
index 6dcc911d6287c10d80f53bfe2a5fc8883fa21c90..11b06f9a451b6bd6e758cc623032bec140b2cf28 100644 |
--- a/build/android/pylib/cmd_helper.py |
+++ b/build/android/pylib/cmd_helper.py |
@@ -6,11 +6,20 @@ |
import os |
import logging |
+import signal |
import subprocess |
+import tempfile |
import constants |
+def _call(args, stdout=None, stderr=None, shell=None, cwd=None): |
frankf
2013/04/09 21:14:05
-> _Call
craigdh
2013/04/09 21:25:00
Done.
|
+ return subprocess.call( |
+ args=args, cwd=cwd, stdout=stdout, stderr=stderr, |
+ shell=shell, close_fds=True, |
+ preexec_fn=lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL)) |
+ |
+ |
def RunCmd(args, cwd=None): |
"""Opens a subprocess to execute a program and returns its return value. |
@@ -24,7 +33,7 @@ def RunCmd(args, cwd=None): |
Return code from the command execution. |
""" |
logging.info(str(args) + ' ' + (cwd or '')) |
- return subprocess.call(args, cwd=cwd) |
+ return _call(args, cwd=cwd) |
def GetCmdOutput(args, cwd=None, shell=False): |
@@ -59,12 +68,17 @@ def GetCmdStatusAndOutput(args, cwd=None, shell=False): |
The tuple (exit code, output). |
""" |
logging.info(str(args) + ' ' + (cwd or '')) |
- p = subprocess.Popen(args=args, cwd=cwd, stdout=subprocess.PIPE, |
- stderr=subprocess.PIPE, shell=shell) |
- stdout, stderr = p.communicate() |
- exit_code = p.returncode |
+ tmpout = tempfile.TemporaryFile(bufsize=0) |
+ tmperr = tempfile.TemporaryFile(bufsize=0) |
+ exit_code = _call(args, cwd=cwd, stdout=tmpout, stderr=tmperr, shell=shell) |
+ tmperr.seek(0) |
+ stderr = tmperr.read() |
+ tmperr.close() |
if stderr: |
logging.critical(stderr) |
+ tmpout.seek(0) |
+ stdout = tmpout.read() |
Isaac (away)
2013/04/09 20:53:54
I think this will have performance cost; possibly
frankf
2013/04/09 21:14:05
I'm not concerned with performance at this point.
craigdh
2013/04/09 21:25:00
Running it locally I haven't observed any noticeab
|
+ tmpout.close() |
logging.info(stdout[:4096]) # Truncate output longer than 4k. |
return (exit_code, stdout) |