I have a c++ program that ssh’s into a server and runs some commands. If the ssh fails, the error is printed on the screen and the program doesnt know about that.. and it returns a blank list of output. How do i know that ssh has failed? is there a way to redirect STDERR to something other than a FD?
Share
I don’t know the way you actually do the ssh.
If you
system(), then I may suggest you to usepopen(). It will allow you to retrieve the output of the program. You’ll be able to read it from a file descriptor, instead of it being displayed. Then, you can append a redirection to you command so that stderr is redirected to stdout, and retrieved in the fd.If you really need your stdout and stderr separated, then you need to implement an advanced
popen()that will also redirect stderr by yourself. You can do it usingdup2()andfork().