Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Struts - A MVC web framework
Tomcat - JSP/Servlet container
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
JSP - A mailing list about Java Server Pages specification and reference
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
use of RunTime class

use of RunTime class

2003-07-28       - By Prashant

 Back
Reply:     1     2     3     4     5     6     7  

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859 (See http://iso-8859.ora-code.com)-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2919.6307" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Verdana size=2>Hi Group,</FONT></DIV>
<DIV><FONT face=Verdana size=2>&nbsp;&nbsp;&nbsp; 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,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <FONT
color=#ff0000>ssh -l &lt;usrname&gt; -p &lt;portname&gt; &lt;ip
address&gt;</FONT></FONT></DIV>
<DIV><FONT face=Verdana size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Then the
system shows following line</FONT></DIV>
<DIV><FONT face=Verdana
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT
color=#ff0000>&lt;Hostname&gt; password:&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
</FONT></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2>&nbsp;&nbsp;&nbsp; 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.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2>&nbsp;&nbsp;&nbsp; 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</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2>&nbsp;&nbsp;&nbsp; import
java.io.*;<BR></FONT></DIV>
<DIV><FONT face=Verdana size=2>&nbsp;&nbsp;&nbsp; public class one{</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
public one() throws Exception{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Runtime
run=Runtime.getRuntime();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; System.out.println("came here
up");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
Process pr=run.exec("ssh -l &lt;usrname&gt; -p &lt;portname&gt; &lt;ip
address&gt;");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; System.out.println("came here
down");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
InputStream in=pr.getInputStream();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
System.out.println(in.available());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; BufferedReader buff=new BufferedReader
(new
InputStreamReader(pr.getInputStream()));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
System.out.println("1");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; String
line=buff.readLine();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("2");<BR></FONT><FONT face=Verdana
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;System.out.println(line);<BR>&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
public static void main(String a[]){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
try{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new
one();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
}catch(Exception ee){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp
;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
ee.printStackTrace();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2>&nbsp;&nbsp;&nbsp; }//end of class</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2>&nbsp;&nbsp;&nbsp;&nbsp;We are getting output
till 'System.out.println("1")' , but the ' System.out.println("2") ' is not
coming at all on the screen.&nbsp;The process remains in the hanged status and
I
think it expects some user input.&nbsp;But I don't understand why it is not
printing '&lt;Hostname&gt; password:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
'
line though I am capturing the input stream of the process.</FONT></DIV>
<DIV><FONT face=Verdana size=2></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2>&nbsp;&nbsp;&nbsp; Can anyone&nbsp;tell me why
this is happening. If anybody has already&nbsp;implemented&nbsp;such kind of
functionality where 'java program will supply the password to connect to the
remote server'</FONT>&nbsp;<FONT face=Verdana size=2> then&nbsp;kindly suggest
us how to do that.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2>Thanx in advance</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2>Prashant</FONT></DIV></BODY></HTML>

©2008 junlu.com - Jax Systems, LLC, U.S.A.