[prev in list] [next in list] [prev in thread] [next in thread] 

List:       whonix-devel
Subject:    [Whonix-devel] How to create a real copy of file descriptors stdout / stderr?
From:       Patrick Schleizer <patrick-mailinglists () whonix ! org>
Date:       2017-02-27 0:03:00
Message-ID: 0900f982-0292-e7bb-776f-086b819df581 () riseup ! net
[Download RAW message or body]

Hi,

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
information.

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.)

#####

#!/bin/bash

temp_dir="$(mktemp --directory)"
logfile="$temp_dir/log"

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?

Cheers,
Patrick

[1]
22% [8 Packages 3,449 kB/7,098 kB 49%]
                                                                  174
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.
_______________________________________________
You are receiving this e-mail because you subscribed Whonix-devel mailing list. To \
unsubscribe visit https://www.whonix.org/cgi-bin/mailman/listinfo/whonix-devel or \
mail "unsubscribe" to Whonix-devel-unsubscribe@whonix.org.

Sie erhalten diese E-Mail, weil Sie die Whonix-devel Mailingliste aboniert haben. Zum \
abbestellen besuchen Sie https://www.whonix.org/cgi-bin/mailman/listinfo/whonix-devel \
oder mailen Sie "unsubscribe" an Whonix-devel-unsubscribe@whonix.org.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic