The following header lines retained to affect attribution:
|Date: Tue, 4 Jan 2000 21:58:34 -0500 (EST)
|From: Brian Wellington <[EMAIL PROTECTED]>
|To: Leo Wierzbowski <[EMAIL PROTECTED]>
|cc: [EMAIL PROTECTED]
|Subject: Re: popen ssh1? stumped...
|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
In SGI Irix and most other Release 6 derived operating systems, getpass(...)
reads from /dev/tty and not file descriptor 2.
getpass(3C) getpass(3C)
NAME
getpass - read a password
SYNOPSIS
#include <stdlib.h>
char *getpass (const char *prompt);
DESCRIPTION
getpass reads up to a newline or EOF from the file /dev/tty, after
prompting on the standard error output with the null-terminated string
prompt and disabling echoing. A pointer is returned to a null-terminated
string of at most 8 characters. If /dev/tty cannot be opened, a null
pointer is returned. An interrupt will terminate input and send an
interrupt signal to the calling program before returning.
FILES
/dev/tty
NOTE
The return value points to static data whose content is overwritten by
each call.
Randolph J. Herber, [EMAIL PROTECTED], +1 630 840 2966, CD/CDFTF PK-149F,
Mail Stop 318, Fermilab, Kirk & Pine Rds., PO Box 500, Batavia, IL 60510-0500,
USA. (Speaking for myself and not for US, US DOE, FNAL nor URA.) (Product,
trade, or service marks herein belong to their respective owners.)