TJCooper has asked for the wisdom of the Perl Monks concerning the following question:
As a solution to recording terminal output into a log file, whilst still viewing output on the terminal (using code within a bash script itself rather than piping to tee on the command-line) I typically use:
exec > >(tee "$DIR/Logs/System.log")Near the top of the bash script.
This bash script eventually invokes a Perl script. Output printed to the terminal comes from both Bash and Perl, however, the inclusion of the above line causes the buffering of the Perl-specific portion of the output such that it's only displayed on the terminal once the script fully completes. Running the Perl script as a standalone provides the intended real-time updates, as does invoking it via Bash without the above line.
Could anybody explain why this is happening and also suggest a solution? The ultimate goal here is to provide real-time feedback to the user on the terminal, whilst keeping a hard-copy of this feedback in a log file.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Printing to STDOUT buffered when invoking Perl within a bash-script using tee
by haukex (Archbishop) on Dec 05, 2016 at 15:06 UTC | |
by TJCooper (Beadle) on Dec 05, 2016 at 15:11 UTC | |
by haukex (Archbishop) on Dec 05, 2016 at 15:24 UTC |