Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3439)

Unified Diff: build/android/pylib/cmd_helper.py

Issue 13861026: [Android] Switch all subprocess.Popen calls to use a temporary file instead of PIPE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/android_commands.py ('k') | build/android/pylib/utils/findbugs.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e9102411a6c71acdf85d3d7e7677ff7b5f18ecb1 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):
+ 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()
+ tmpout.close()
logging.info(stdout[:4096]) # Truncate output longer than 4k.
return (exit_code, stdout)
« no previous file with comments | « build/android/pylib/android_commands.py ('k') | build/android/pylib/utils/findbugs.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698