Skip to content

Commit f4ca02f

Browse files
also redirect JL_STDERR etc. when redirecting to devnull
1 parent fbb3e11 commit f4ca02f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

base/stream.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,14 @@ function _redirect_io_libc(stream, unix_fd::Int)
12441244
dup(posix_fd, RawFD(unix_fd))
12451245
nothing
12461246
end
1247+
function _set_cglobal_stdio(handle::Union{LibuvStream, IOStream}, unix_fd::Int)
1248+
c_sym = unix_fd == 0 ? cglobal(:jl_uv_stdin, Ptr{Cvoid}) :
1249+
unix_fd == 1 ? cglobal(:jl_uv_stdout, Ptr{Cvoid}) :
1250+
unix_fd == 2 ? cglobal(:jl_uv_stderr, Ptr{Cvoid}) :
1251+
C_NULL
1252+
c_sym == C_NULL || unsafe_store!(c_sym, handle.handle)
1253+
nothing
1254+
end
12471255
function _redirect_io_global(io, unix_fd::Int)
12481256
unix_fd == 0 && (global stdin = io)
12491257
unix_fd == 1 && (global stdout = io)
@@ -1252,18 +1260,15 @@ function _redirect_io_global(io, unix_fd::Int)
12521260
end
12531261
function (f::RedirectStdStream)(handle::Union{LibuvStream, IOStream})
12541262
_redirect_io_libc(handle, f.unix_fd)
1255-
c_sym = f.unix_fd == 0 ? cglobal(:jl_uv_stdin, Ptr{Cvoid}) :
1256-
f.unix_fd == 1 ? cglobal(:jl_uv_stdout, Ptr{Cvoid}) :
1257-
f.unix_fd == 2 ? cglobal(:jl_uv_stderr, Ptr{Cvoid}) :
1258-
C_NULL
1259-
c_sym == C_NULL || unsafe_store!(c_sym, handle.handle)
1263+
_set_cglobal_stdio(handle, f.unix_fd)
12601264
_redirect_io_global(handle, f.unix_fd)
12611265
return handle
12621266
end
12631267
function (f::RedirectStdStream)(::DevNull)
12641268
nulldev = @static Sys.iswindows() ? "NUL" : "/dev/null"
12651269
handle = open(nulldev, write=f.writable)
12661270
_redirect_io_libc(handle, f.unix_fd)
1271+
_set_cglobal_stdio(handle, f.unix_fd)
12671272
close(handle) # handle has been dup'ed in _redirect_io_libc
12681273
_redirect_io_global(devnull, f.unix_fd)
12691274
return devnull

0 commit comments

Comments
 (0)