On the monitored application side, there is a way to redirect both outputs to an outbound connection, using netcat:
$ ./application 2>&1 | nc <remote-host> <remote-port>
This way, you're redirecting stderr
to stdout
and then pipe it all together to netcat, which will take care of setting up the socket, establish connection with the remote host and all that stuff.
However, bear in mind that you can suffer from printf()
's buffering, if that's the function you're using to write to stdout
. In my local tests, I've seen that the data sent to stderr
by the application is seen immediately on the other listening end, but on the other hand the data sent to stdout
is only sent when the application exits or there's enough data in the buffer to flush it all at once. So, if you care about the order and the availability of the info on the monitoring side, I'd suggest you to place calls to fflush(stdout);
whenever you print something interesting to stdout
, or replace the calls to printf()
, fprintf()
and the like to write()
, which does not buffer. The downside is that you have to touch the code of the application, of course, but I don't know any way to externally force flushing of an application's output buffers (i.e. from bash).