How to duplicate stdout/stderr?

I’m looking for a way to duplicate stdout/stderr. I’m aware of I/O and Network · The Julia Language which is great, but unfortunately it captures stdout instead of duplicating it.

In python I use:

logfile = tempfile.NamedTemporaryFile()
tee = subprocess.Popen(["tee", logfile.name], stdin=subprocess.PIPE)
# Cause tee's stdin to get a copy of our stdin/stdout (as well as that of any
# child processes we spawn).
os.dup2(tee.stdin.fileno(), sys.stdout.fileno())
os.dup2(tee.stdin.fileno(), sys.stderr.fileno())

and that worked wonders. Is there any way to accomplish this in Julia?

1 Like