Stdio tee (copy without redirection)

Dear all,

I would like to make something like Base.redirect_stdio, but which copies elsewhere the stdout and stderr without suppressing them, like the tee command.

Would you know how to do this ?
Thanks a lot,

Please check this similar thread and this.

Many thanks, but I have this error (private file names redacted):

ERROR: LoadError: MethodError: no method matching (::Base.RedirectStdStream)(::Tee{Tuple{Base.TTY, Base.TTY}})
The function Base.RedirectStdStream(2, true) exists, but no method is defined for this combination of argument types.

Closest candidates are:
(::Base.RedirectStdStream)()
@ Base stream.jl:1293
(::Base.RedirectStdStream)(::Pipe)
@ Base stream.jl:1285
(::Base.RedirectStdStream)(::Base.DevNull)
@ Base stream.jl:1271

Stacktrace:
[1] redirect_stdio(; stdin::Nothing, stderr::Tee{Tuple{Base.TTY, Base.TTY}}, stdout::Tee{Tuple{Base.TTY, Base.TTY}})
@ Base ./stream.jl:1355
[2] redirect_stdio(f::var"#logstdio##0#logstdio##1"{var"#11#12"}; stdin::Nothing, stderr::Tee{Tuple{Base.TTY, Base.TTY}}, stdout::Tee{Tuple{Base.TTY, Base.TTY}})
@ Base ./stream.jl:1445
[3] logstdio(f::var"#11#12")
@ Main XXXXXXXXXXXXXXX
[4] top-level scope
@ XXXXXXXXXXXXXX
[5] include(mod::Module, _path::String)
@ Base ./Base.jl:306
[6] exec_options(opts::Base.JLOptions)
@ Base ./client.jl:317
[7] _start()
@ Base ./client.jl:550
in expression starting at XXXXXXXXXXX

I will dig a little by myself and return here in a few hours.

Update: it seems the redirect_stdio function does not work with more complex structures than fd integers:

struct RedirectStdStream <: Function
    unix_fd::Int
    writable::Bool
end
for (f, writable, unix_fd) in
        ((:redirect_stdin, false, 0),
         (:redirect_stdout, true, 1),
         (:redirect_stderr, true, 2))
    @eval const ($f) = RedirectStdStream($unix_fd, $writable)
end
function redirect_stdio(;stdin=nothing, stderr=nothing, stdout=nothing)
    stdin  === nothing || redirect_stdin(stdin)
    stderr === nothing || redirect_stderr(stderr)
    stdout === nothing || redirect_stdout(stdout)
end