Getting output of command from run(pipeline(...)) in both stdout and file


I’m trying to write a small script to setup simulations in a cluster. These take a while to compute, and while doing so provide useful output informing of the state of the simulation. For that purpose, when using bash, I’d run this as:

./rn | tee out.txt

where rn runs the simulations itself. Doing this gives me all the output in stdout, which is useful as the queuing system captures it and I can use it to evaluate the state of simulations during runtime. But I also want all that output to be saved together with the rest of the simulation output, which is why I use tee in here. In julia I could do:

run(pipeline(`./rn`, "out.txt"))

but that will silence everything coming to stdout. So is there a way to do both using run(pipeline(...))?

run(pipeline(`./rn`, `tee out.txt`))

You could use OutputCollectors.jl, it’s very handy for this: OutputCollectors.jl Documentation · OutputCollectors.jl

Thanks @Jeff_Emanuel , that is precisely what I was looking for. @ericphanson , OutputCollectors.jl looks very useful, although in this case I want to see if everything I’m trying to do can be achieved with base julia.