I would not expect this solution to work, as I believe ssh opens /dev/tty for the password, not reading it from stdin. (See e.g., sshconnect2.c and readpass.c in openssh-3.4p1).
TW
At 12:17 AM 07/28/03, you wrote:
>try putting pr.waitFor() after
>Process pr=run.exec("ssh -l <usrname> -p <portname> <ip address>");
>
>it waits for the process to get executed before executing next statement.
>
>HTH,
>uthiresh
>
>
>-----Original Message-----
>From: A mailing list for Java(tm) 2 Platform, Enterprise Edition
>[mailto:J2EE-INTEREST@(protected)
>Sent: Monday, July 28, 2003 12:25 PM
>To: J2EE-INTEREST@(protected)
>Subject: use of RunTime class
>
>
>Hi Group,
> We are developing an application which requires connecting to the remote
>server using ssh protocol. If I have to connect to that server from command
>prompt then I type command something like below,
>
> ssh -l <usrname> -p <portname> <ip address>
> Then the system shows following line
> <Hostname> password:
>
>
> Then the remote server ask for password (We don't want to use public and
>private key automatic validation) ,which I enter manually and I get the
>connection to the remote server.
>
> Now the same functionality we want to duplicate in a java program. So we
>thought of using Runtime class to execute the command mentioned above. The
>sample code for that is given below
>
>
> import java.io.*;
>
> public class one{
>
> public one() throws Exception{
> Runtime run=Runtime.getRuntime();
> System.out.println("came here up");
> Process pr=run.exec("ssh -l <usrname> -p <portname> <ip
>address>");
> System.out.println("came here down");
> InputStream in=pr.getInputStream();
> System.out.println(in.available());
> BufferedReader buff=new BufferedReader(new
>InputStreamReader(pr.getInputStream()));
> System.out.println("1");
> String line=buff.readLine();
> System.out.println("2");
> System.out.println(line);
> }
>
> public static void main(String a[]){
> try{
> new one();
> }catch(Exception ee){
> ee.printStackTrace();
> }
> }
>
> }//end of class
>
>
> We are getting output till 'System.out.println("1")' , but the '
>System.out.println("2") ' is not coming at all on the screen. The process
>remains in the hanged status and I think it expects some user input. But I
>don't understand why it is not printing '<Hostname> password: ' line
>though I am capturing the input stream of the process.
>
>
> Can anyone tell me why this is happening. If anybody has already
>implemented such kind of functionality where 'java program will supply the
>password to connect to the remote server' then kindly suggest us how to do
>that.
>
>Thanx in advance
>
>Prashant
>
>===========================================================================
>To unsubscribe, send email to listserv@(protected)
>of the message "signoff J2EE-INTEREST". For general help, send email to
>listserv@(protected)".
===========================================================================
To unsubscribe, send email to listserv@(protected)
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".