Question

I have a specific problem I'd like to solve and I'm running system through perl which I think runs in bash:

  1. Show stdout and stderr in both.log. Add "done" if it finished.
  2. Append stderr in stderr.log
  3. Don't print out to terminal, except the original command and "done" if the command finished.

So once we combine stdout and stderr, can we separate them again? OR can we first capture stderr and then combine it with stdout after?

Was it helpful?

Solution

bash: system("((" . $cmd . " 2>&1 1>&3 | tee -a stderr.log) 3>&1) > both.log; echo done | tee -a both.log"

Even though we use tee for stderr.log it doesn't tee the error output to the terminal (which is what I want). I don't completely understand how it works, but I guess the tee causes it to go to the log file and also to the next file descriptor equation.


Bonus

I found this here in the comments: http://wiki.bash-hackers.org/howto/redirection_tutorial This can be used to do the same thing, but all output is also teed to terminal (It doesn't print "done").

bash: (($command 2>&1 1>&3 | tee stderr.log) 3>&1 ) | tee both.log


Using Perl 5.14.1.

OTHER TIPS

tcsh alone would not suffice here. It does not support redirecting stderr without stdout.

Use another shell or a designated script.

More here.


UPDATE:

Can this be ported to tcsh?

No. tcsh does not support redirecting stderr without stdout.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top