@@ -148,6 +148,12 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
148
148
if not stderrRedirected :
149
149
args .append ("2>" + tmpFileStderrName )
150
150
151
+ # Sanitize encoding. None is not a valid encoding.
152
+ if stdout .encoding is None :
153
+ stdout .encoding = 'utf-8'
154
+ if stderr .encoding is None :
155
+ stderr .encoding = 'utf-8'
156
+
151
157
# actually do the spawn
152
158
try :
153
159
args = [sh , '/C' , escape (' ' .join (args ))]
@@ -167,7 +173,7 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
167
173
try :
168
174
with open (tmpFileStdoutName , "rb" ) as tmpFileStdout :
169
175
output = tmpFileStdout .read ()
170
- stdout .write (output .decode (stdout .encoding if stdout . encoding is not None else 'utf-8' , "replace" ))
176
+ stdout .write (output .decode (stdout .encoding , "replace" ))
171
177
os .remove (tmpFileStdoutName )
172
178
except OSError :
173
179
pass
@@ -176,7 +182,7 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
176
182
try :
177
183
with open (tmpFileStderrName , "rb" ) as tmpFileStderr :
178
184
errors = tmpFileStderr .read ()
179
- stderr .write (errors .decode (stderr .encoding if stderr . encoding is not None else 'utf-8' , "replace" ))
185
+ stderr .write (errors .decode (stderr .encoding , "replace" ))
180
186
os .remove (tmpFileStderrName )
181
187
except OSError :
182
188
pass
0 commit comments