2

I have a long running process which is writing status information to stdout, and logging debug information to stderr.

I would like to pipe the stderr output to logger, so that anything written to stderr actually ends up going to syslog, while at the same time being able to read the process' stdout.

Is it possible to do this?

1 Answers1

2
{ cmd 2>&1 >&3 3>&- | logger 3>&-; } 3>&1

The idea being that the outer stdout is duplicated onto file descriptor (fd) 3, and restored for cmd onto stdout, while cmd's file descriptor 2 (stderr) itself goes to the pipe to logger.

The 3>&- is to close that fd for both the cmd and logger commands after it has served its purpose as those commands won't need/use it.