@@ -110,7 +110,13 @@ def get_installdir():
110110 return os .path .abspath (os .path .dirname (os .path .dirname (__file__ )))
111111
112112
113- def stream_command (cmd , no_newline_regexp = "Progess" , sudo = False , sudo_options = None ):
113+ def stream_command (
114+ cmd ,
115+ no_newline_regexp = "Progess" ,
116+ sudo = False ,
117+ sudo_options = None ,
118+ output_type = "stdout" ,
119+ ):
114120 """stream a command (yield) back to the user, as each line is available.
115121
116122 # Example usage:
@@ -127,14 +133,25 @@ def stream_command(cmd, no_newline_regexp="Progess", sudo=False, sudo_options=No
127133 sudo_options: string or list of strings that will be passed as options to sudo
128134
129135 """
136+ if output_type not in ["stdout" , "stderr" ]:
137+ bot .exit ("Invalid output type %s. Must be stderr or stdout." % output_type )
130138 cmd = _process_sudo_cmd (cmd , sudo , sudo_options )
131139
132140 process = subprocess .Popen (
133141 cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , universal_newlines = True
134142 )
135- for line in iter (process .stdout .readline , "" ):
143+
144+ # Allow the runner to choose streaming output or error
145+ stream = process .stdout .readline
146+ if output_type == "stderr" :
147+ stream = process .stderr .readline
148+
149+ # Stream lines back to the caller
150+ for line in iter (stream , "" ):
136151 if not re .search (no_newline_regexp , line ):
137152 yield line
153+
154+ # If there is an error, raise.
138155 process .stdout .close ()
139156 return_code = process .wait ()
140157 if return_code :
0 commit comments