jmlynesjr has asked for the wisdom of the Perl Monks concerning the following question:

While this is somewhat off topic, I am sure that among the Perl Monks are also some Shell Monks...

In updating/re-testing my wxPerl installer script for Ubuntu 14.04LTS based on some good feedback to my eariler post, I discovered that my suggested invocation statement   sh -v wxPerl-Installer.sh > ~Perl/wxPerl-Installer.log was hanging up when something inside the process issued a prompt that wasn't visible on the screen(being hidden in the log file). Other than losing the prompt the mix of screen display vs. log file output is good.

I'm currently using   sh -v wxPerl-Installer.sh 2>&1 | tee wxPerl-Installer.log, but this command sends the mass amount of compiler info(+/- 2MB) to the screen as well as to the log file.

So, can I have it both ways? The display provided by command one without losing the prompts while sending the mass of compiler output only to the log file.

Thanks for your assistance.

Update1:

Thanks for the hints. What I finally decided I wanted for logging was STDOUT containing the mass of compiler output going to a file, STDERR containing a copy of the script(sh -v) and prompts and errors going to the screen and to a file. After much search I arrived at    sh -v wxPerl-Installer.sh 2>&1 >wxPerl-Installer.log | tee wxPerl-Installer.screen

James

There's never enough time to do it right, but always enough time to do it over...

Replies are listed 'Best First'.
Re: wxperl Installer Script Logging
by rmcgowan (Sexton) on Oct 22, 2014 at 21:06 UTC

    Based on your description, I would say that the 'something inside' is either redirecting stderr to stdout, or it writes the prompt on stdout to begin with.

    Standard shells write the prompt to stderr, which you can prove for yourself by running:

    ksh -i > ksh_tst.out

    You will see a prompt, plus command line input, but no command generates any visible output, because it goes into the file.

    You will need to determine what is generating the prompt, and see if you can fix it to write to stderr.

Re: wxperl Installer Script Logging
by Loops (Curate) on Oct 22, 2014 at 23:39 UTC

    You may be able to avoid input prompts as suggested above, but in situations where you can't, one option is to print the last few lines after no output is detected for awhile. So output is suppressed unless the installer is sitting at a prompt for a bit. Usually the extra few seconds don't matter if the user is waiting for a long compile anyway.

    The script below will act like a null sink until output quieces, then it will print the most recent 5 output lines. Pipe the output of tee in your current command line into:

    my $timeout = 10; # Seconds to wait, before printing select *STDOUT; $| = 1; # Set standard output to auto flush while (1) { my $buf = my $in = ''; eval { local $SIG{ALRM} = sub { print $buf,$in; die }; while (1) { alarm $timeout; sysread *STDIN, $in, 500 or exit; alarm 0; ($buf) = ($buf.$in) =~ m/((.*?\n){0,4}.*?\n?)$/; $in = ''; } } }
Re: wxperl Installer Script Logging
by Anonymous Monk on Oct 22, 2014 at 22:07 UTC