@@ -177,19 +177,20 @@ def run_process(cmd, check=True, input=None, *args, **kw):
177
177
178
178
debug_text = '%sexecuted %s' % ('successfully ' if check else '' , ' ' .join (cmd ))
179
179
180
- if hasattr (subprocess , "run" ):
181
- ret = subprocess .run (cmd , check = check , input = input , * args , ** kw )
182
- logger .debug (debug_text )
183
- return ret
180
+ if hasattr (subprocess , 'run' ):
181
+ # Python 3.5 and above only
182
+ kw .setdefault ('encoding' , 'utf-8' )
183
+ result = subprocess .run (cmd , check = check , input = input , * args , ** kw )
184
+ else :
185
+ # Python 2 compatibility: Introduce Python 3 subprocess.run-like behavior
186
+ if input is not None :
187
+ kw ['stdin' ] = subprocess .PIPE
188
+ proc = Popen (cmd , * args , ** kw )
189
+ stdout , stderr = proc .communicate (input )
190
+ result = Py2CompletedProcess (cmd , proc .returncode , stdout , stderr )
191
+ if check :
192
+ result .check_returncode ()
184
193
185
- # Python 2 compatibility: Introduce Python 3 subprocess.run-like behavior
186
- if input is not None :
187
- kw ['stdin' ] = subprocess .PIPE
188
- proc = Popen (cmd , * args , ** kw )
189
- stdout , stderr = proc .communicate (input )
190
- result = Py2CompletedProcess (cmd , proc .returncode , stdout , stderr )
191
- if check :
192
- result .check_returncode ()
193
194
logger .debug (debug_text )
194
195
return result
195
196
0 commit comments