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

Side by Side Diff: build/android/cmd_helper.py

Issue 10693110: [android] Split top-level scripts and libraries from build/android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Copyright on __init__.py, removed #! on some pylib/ files. Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/chrome_test_server_spawner.py ('k') | build/android/debug_info.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """A wrapper for subprocess to make calling shell commands easier."""
8
9
10 import logging
11 import subprocess
12
13
14 def RunCmd(args, cwd=None):
15 """Opens a subprocess to execute a program and returns its return value.
16
17 Args:
18 args: A string or a sequence of program arguments. The program to execute is
19 the string or the first item in the args sequence.
20 cwd: If not None, the subprocess's current directory will be changed to
21 |cwd| before it's executed.
22
23 Returns:
24 Return code from the command execution.
25 """
26 logging.info(str(args) + ' ' + (cwd or ''))
27 p = subprocess.Popen(args=args, cwd=cwd)
28 return p.wait()
29
30
31 def GetCmdOutput(args, cwd=None, shell=False):
32 """Open a subprocess to execute a program and returns its output.
33
34 Args:
35 args: A string or a sequence of program arguments. The program to execute is
36 the string or the first item in the args sequence.
37 cwd: If not None, the subprocess's current directory will be changed to
38 |cwd| before it's executed.
39 shell: Whether to execute args as a shell command.
40
41 Returns:
42 Captures and returns the command's stdout.
43 Prints the command's stderr to logger (which defaults to stdout).
44 """
45 logging.info(str(args) + ' ' + (cwd or ''))
46 p = subprocess.Popen(args=args, cwd=cwd, stdout=subprocess.PIPE,
47 stderr=subprocess.PIPE, shell=shell)
48 stdout, stderr = p.communicate()
49 if stderr:
50 logging.critical(stderr)
51 logging.info(stdout[:4096]) # Truncate output longer than 4k.
52 return stdout
OLDNEW
« no previous file with comments | « build/android/chrome_test_server_spawner.py ('k') | build/android/debug_info.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698