@@ -60,6 +60,13 @@ def _print_command(dry_run, command, env=None, prompt="+ "):
60
60
61
61
62
62
def call (command , stderr = None , env = None , dry_run = None , print_command = True ):
63
+ """
64
+ call(command, ...) -> str
65
+
66
+ Execute the given command.
67
+
68
+ This function will raise an exception on any command failure.
69
+ """
63
70
dry_run = _coerce_dry_run (dry_run )
64
71
if dry_run or print_command :
65
72
_print_command (dry_run , command , env = env )
@@ -81,6 +88,35 @@ def call(command, stderr=None, env=None, dry_run=None, print_command=True):
81
88
"': " + e .strerror )
82
89
83
90
91
+ def capture (command , stderr = None , env = None , dry_run = None , print_command = True ):
92
+ """
93
+ capture(command, ...) -> str
94
+
95
+ Execute the given command and return the standard output.
96
+
97
+ This function will raise an exception on any command failure.
98
+ """
99
+ dry_run = _coerce_dry_run (dry_run )
100
+ if dry_run or print_command :
101
+ _print_command (dry_run , command , env = env )
102
+ if dry_run :
103
+ return
104
+ _env = None
105
+ if env is not None :
106
+ _env = dict (os .environ )
107
+ _env .update (env )
108
+ try :
109
+ return subprocess .check_output (command , env = _env , stderr = stderr )
110
+ except subprocess .CalledProcessError as e :
111
+ diagnostics .fatal (
112
+ "command terminated with a non-zero exit status " +
113
+ str (e .returncode ) + ", aborting" )
114
+ except OSError as e :
115
+ diagnostics .fatal (
116
+ "could not execute '" + quote_command (command ) +
117
+ "': " + e .strerror )
118
+
119
+
84
120
@contextmanager
85
121
def pushd (path , dry_run = None , print_command = True ):
86
122
dry_run = _coerce_dry_run (dry_run )
0 commit comments