Browse Source

Fix stdio stream redirection on Julia 1.6.

master
Fredrik Ekre 4 years ago
parent
commit
1341def98d
  1. 2
      Project.toml
  2. 13
      src/TeeStreams.jl

2
Project.toml

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
name = "TeeStreams"
uuid = "c24d529b-c83e-40e0-9fc3-05832c05a0ba"
version = "1.1.0"
version = "1.1.1"
[compat]
julia = "1.5"

13
src/TeeStreams.jl

@ -122,12 +122,23 @@ end @@ -122,12 +122,23 @@ end
# Adapted from Logging2.jl (MIT License: Copyright (c) 2020 Chris Foster)
# https://github.com/JuliaLogging/Logging2.jl/blob/094eb6619aeaa8815585dbe7f33b4972f9a4ce6b/src/Logging2.jl#L12-L37
function (redirect_func::Base.RedirectStdStream)(f::Function, io::TeeStream)
if VERSION >= v"1.7.0-DEV.254"
function (redirect_func::Base.RedirectStdStream)(f::Function, io::TeeStream)
prev_stream =
redirect_func.unix_fd == 1 ? stdout :
redirect_func.unix_fd == 2 ? stderr :
throw(ArgumentError("Can only redirect stdout and stderr to TeeStream."))
return _redirect_internal(f, io, redirect_func, prev_stream)
end
else
Base.redirect_stdout(f::Function, io::TeeStream) =
_redirect_internal(f, io, redirect_stdout, stdout)
Base.redirect_stderr(f::Function, io::TeeStream) =
_redirect_internal(f, io, redirect_stderr, stderr)
end
function _redirect_internal(f, io, redirect_func, prev_stream)
result = nothing
rd, rw = redirect_func()

Loading…
Cancel
Save