@@ -20,9 +20,6 @@ def __init__(self, command, message):
20
20
# Don't use close_fds on Windows.
21
21
kUseCloseFDs = not kIsWindows
22
22
23
- # Use temporary files to replace /dev/null on Windows.
24
- kAvoidDevNull = kIsWindows
25
-
26
23
class ShellEnvironment (object ):
27
24
28
25
"""Mutable shell environment containing things like CWD and env vars.
@@ -192,7 +189,6 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
192
189
input = subprocess .PIPE
193
190
stderrTempFiles = []
194
191
opened_files = []
195
- named_temp_files = []
196
192
# To avoid deadlock, we use a single stderr stream for piped
197
193
# output. This is null until we have seen some output using
198
194
# stderr.
@@ -256,8 +252,8 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
256
252
else :
257
253
if r [2 ] is None :
258
254
redir_filename = None
259
- if kAvoidDevNull and r [0 ] == '/dev/null' :
260
- r [2 ] = tempfile . TemporaryFile ( mode = r [1 ])
255
+ if kIsWindows and r [0 ] == '/dev/null' :
256
+ r [2 ] = open ( os . devnull , r [1 ])
261
257
elif kIsWindows and r [0 ] == '/dev/tty' :
262
258
# Simulate /dev/tty on Windows.
263
259
# "CON" is a special filename for the console.
@@ -306,14 +302,11 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
306
302
if not executable :
307
303
raise InternalShellError (j , '%r: command not found' % j .args [0 ])
308
304
309
- # Replace uses of /dev/null with temporary files.
310
- if kAvoidDevNull :
305
+ if kIsWindows :
306
+ # Replace uses of /dev/null with the Windows equivalent.
311
307
for i ,arg in enumerate (args ):
312
308
if arg == "/dev/null" :
313
- f = tempfile .NamedTemporaryFile (delete = False )
314
- f .close ()
315
- named_temp_files .append (f .name )
316
- args [i ] = f .name
309
+ args [i ] = os .devnull
317
310
318
311
try :
319
312
procs .append (subprocess .Popen (args , cwd = cmd_shenv .cwd ,
@@ -422,13 +415,6 @@ def to_string(bytes):
422
415
else :
423
416
exitCode = res
424
417
425
- # Remove any named temporary files we created.
426
- for f in named_temp_files :
427
- try :
428
- os .remove (f )
429
- except OSError :
430
- pass
431
-
432
418
if cmd .negate :
433
419
exitCode = not exitCode
434
420
0 commit comments