dcsimg
How to use the ssh command with Runtime.exec()?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Adriana_Quero
Posted On:   Wednesday, November 6, 2002 08:21 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 an JApplet

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

   <<Less

Re: How to use the ssh command with Runtime.exec()?

Posted By:   Christopher_Koenigsberg  
Posted On:   Wednesday, November 6, 2002 08:32 AM

You need to provide an array, to "exec", where the first element is the executable ("ssh") and the subsequent elements are the runtime args (in your case, two args "-l adriana", and "leibniz.faces.ula.ve").



It's cryptic but the Unix ("foo not found") means that it is literally looking for an executable program or shellscript on your search path, with the exact name "foo". In your case it was trying to look for a file with name being your whole command line "ssh -l adriana leibniz.faces.ula.ve"....

About | Sitemap | Contact