[Whonix-devel] How to create a real copy of file descriptors stdout / stderr?

Patrick Schleizer patrick-mailinglists at whonix.org
Mon Feb 27 01:03:00 CET 2017


my goal is to duplicate, redirect all output (stdout and stderr) of an
application (apt-get) to a file while retaining the usual behavior of
apt-get, stdout and stderr.

How to create a real copy of file descriptor stdout and stderr? I would
like to keep stdout and stderr as "natural" as possible. I.e. if it was
running for example apt-get, I would wish to retain colors and progress

By using `tee`, colors and progress information [1] are lost. Therefore
I experimented with using `unbuffer`, however I would appreciate if both
`unbuffer` and `tee` would not required. [2]

The following example is partially functional. (The wrapper does more
stuff, just kept it simple.)



temp_dir="$(mktemp --directory)"

exec 3>&1
exec 1> >(tee -a "$logfile")

#exec 4>&2
#exec 2> >(tee -a "$logfile")

unbuffer apt-get "$@"


Broken: stderr redirection. Once I enable...

exec 4>&2
exec 2> >(tee -a "$logfile")

...nothing gets written to stdout anymore. Could you advice please on
how to fix this?


22% [8 Packages 3,449 kB/7,098 kB 49%]
kB/s 4min 57s
[2] To keep the wrapper simpler and dependent on less external binaries.
Otherwise this could cause conflicts with mandatory access control and
so forth.

More information about the Whonix-devel mailing list