I came up with the start of a possible implementation at Allow pass-through of output by goerz · Pull Request #20 · JuliaDocs/IOCapture.jl · GitHub
The core of it is this snippet:
output = IOBuffer()
temp = IOBuffer()
buffer_redirect_task = @async begin
write(temp, pipe)
temp_data = take!(temp)
write(output, temp_data)
write(default_stdout, temp_data)
end
See also my comment at Add a `tee` option · Issue #19 · JuliaDocs/IOCapture.jl · GitHub
If there’s any low-level IO expert who could weigh in on whether this is a sane approach, please leave a comment on the issue or PR.
I also played around a little with the Tee
struct from Write to file and stdout - #3 by Tamas_Papp, but it doesn’t seem like redirect_stdout
can be called with a Tee
object. If someone knows how to define the appropriate method of redirect_stdout
to make that work, that would still be a possible alternative.