How to use Runtime.exec() to call ssh and scp under Red Hat Linux using JApplet?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Adriana_Quero
Posted On:   Wednesday, November 6, 2002 08:25 AM

I have a problem using Runtime.exec() under Linux..I have this code: private void conectarSSH(){ BufferedReader in = null; BufferedReader error = null; String[] command = {"ssh -l adriana leibniz.faces.ula.ve"}; Runtime rt = Runtime.getRuntime(); try{ Process proc = rt.exec(command); String res = new String(); if(proc != null) { in = new BufferedReader(new InputStreamReader(proc.getInputStream())); error = new BufferedReader(new InputStreamReader(proc.getErrorStream()));    More>>

I have a problem using Runtime.exec() under Linux..I have this code:


private void conectarSSH(){


BufferedReader in = null;


BufferedReader error = null;


String[] command = {"ssh -l adriana leibniz.faces.ula.ve"};


Runtime rt = Runtime.getRuntime();


try{


Process proc = rt.exec(command);


String res = new String();


if(proc != null) {


in = new BufferedReader(new


InputStreamReader(proc.getInputStream()));


error = new BufferedReader(new


InputStreamReader(proc.getErrorStream()));


while(in.ready()) {


res = res + in.readLine();


System.out.println("SSH " + res);
}


while(error.ready()) {



res = res + error.readLine();


System.out.println("SSH " + res);
}


System.out.println("Response " + res);


proc.waitFor();


if(proc.exitValue() != 0) {


System.err.println("Exit val non zero");


}

}



}catch(Exception e){


e.printStackTrace();
}




}


But I have this Exception:


java.io.IOException: ssh -l adriana leibniz.faces.ula.ve: not found


at java.lang.UNIXProcess.forkAndExec(Native Method)


at java.lang.UNIXProcess. (UNIXProcess.java:139)


at java.lang.Runtime.execInternal(Native Method)


at java.lang.Runtime.exec(Runtime.java:550)


at java.lang.Runtime.exec(Runtime.java:475)


at java.lang.Runtime.exec(Runtime.java:441)....


I'm using Red Hat 7.3 and a JApplet


I hope you can help..PLEASE
Thanks a lot..

   <<Less

Re: How to use Runtime.exec() to call ssh and scp under Red Hat Linux using JApplet?

Posted By:   Laxman_Subramanian  
Posted On:   Monday, November 11, 2002 01:08 PM

Did you just try executing just SSH with no parameters using runtime.exec ?
if that works then ssh is in the path and u can execute else give it the absolute path

like
String[] command = new String[3];
command[0] = "/usr/bin/ssh" ;
command[1] = "-l" ;
command[2] = "leibniz.faces.ula.ve";

Try this .
Laxman

for more on exec check this
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
About | Sitemap | Contact