문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top