On Tue, 4 Jan 2000, Leo Wierzbowski wrote:
> I can execute ssh from my C program, to run a program on a remote host and
> then disconnect (e.g., system(ssh host /path/pgm). Now I need to execute
> ssh such that the connection to the remote host stays open while the
> program on the remote host reads stdin for its input. This works OK when I
> use the keyboard to ssh host /path/pgm, but when I popen for writing it
> appears that stdin is not receiving anything. I've read that ssh1 might
> only communicate via tty device, and ignore stdin from popen. If you know
> how to pipe to ssh, please post or email me. I would greatly appreciate
> it. Thanks.
The sftp program I wrote contains a client that talks to an ssh client and
a server executed from the ssh server. It doesn't use a pipe, since I was
never able to get that to work. I had more luck doing something like:
socketpair(s)
fork()
parent:
close(s[1])
use s[0] to talk to ssh client
child:
close(s[0])
dup2(s[1], 0);
dup2(s[1], 1);
exec(ssh)
So, stdin and stdout from ssh are redirected to the socket open in the
parent. stderr is not redirected, since the password entry code really
does need to read from the tty.
Look in ftp://ftp.xbill.org/pub/sftp/ for the newest version of sftp if
you want to see the exact code.
Brian