2

Possible Duplicate:
pipe stdout and stderr to two different processes in shell script?

I have a program which writes to stdout and stderr, I want to pipe the stdout into the stdin of the logger command and pipe the stderr into the stdin of another logger command where the facility, priority and tag are different from the first logger command.

This command is run in the exec stanza of an upstart script on Ubuntu. Also I tried with subshells but it did not work.

Any idea how could I do this?

Thanks! :)

Community
  • 1
  • 1
Remy
  • 334
  • 1
  • 4
  • 15
  • here is a possible solution (not mine, therefore not an answer) http://forums.fedoraforum.org/showthread.php?t=201837 – Erich Kitzmueller Oct 30 '12 at 12:25
  • @ammoQ - I see no problem in posting a link as an answer (with a precis in case the linked article disappears). It's an answer after all, and you found it :-) – Brian Agnew Oct 30 '12 at 12:29
  • @BrianAgnew: Since I don't know if it is a good solution, or even works at all, I rather don't post something I have just googled as an answer. – Erich Kitzmueller Oct 30 '12 at 12:39

1 Answers1

3

Try this:

logger 2>&1 | logger

Explanation: logger 2>&1 will redirect the standard error (file descriptor 2) to the standard output (file descriptor 1), then | logger will pipe that to the standard input of another instance of the logger command.

  • I'm not sure that's right. I think stderr should go to somewhere distinct from stdout ? – Brian Agnew Oct 30 '12 at 12:22
  • @BrianAgnew I don't know if that's possible (using simple shell commands at least). How would you do that? –  Oct 30 '12 at 12:24
  • Hi @BrianAgnew, thanks for posting. But logger doesn't output anything. logger is an utility command to write message to syslog. I want to write stderr and stdout of my program into logger, but on logger with different facility, priority and tags. I want something like this `program 1> logger -p local0.info -t test_info 2> logger -p local0.error -t test_error`, unfortunately redirection is only for files. – Remy Oct 30 '12 at 12:39