Discussion:
[JSch-users] Running ssh command with proxy on MAC
Mohamed Boussaa
2015-12-22 15:44:04 UTC
Permalink
I am running this command on my mac terminal :

ssh -t -o "ProxyCommand ssh ***@10.0.0.1 nc %h %p 22" ***@10.0.0.22 "ls -l"

It works. But when I run it like below in eclipse:

List<String> result = new ArrayList<String>();

java.lang.Process pp;

try {

pp = Runtime.getRuntime().exec("ssh -t -o ProxyCommand ssh
***@10.0.0.1 nc %h %p 22 ***@10.0.0.22 ls -l");

pp.waitFor();

BufferedReader br = new BufferedReader(new
InputStreamReader(pp.getInputStream()));

String line = "";

while ((line = br.readLine()) != null) {

System.out.println("line :"+line);

result.add(line);

}

} catch (IOException e) {

e.printStackTrace();

} catch (InterruptedException e) {

e.printStackTrace();

}


It doest not work and does not print any thing on the console.

Do you have an idea ?

------------------------------------------------------------------------------
vikas barsaiyan
2015-12-30 09:56:27 UTC
Permalink
Your command will run on shell/terminal. So you need to take shell first
the run your command

String[] cmd = {"/bin/sh",
"-c",
Post by Mohamed Boussaa
List<String> result = new ArrayList<String>();
java.lang.Process pp;
try {
pp = Runtime.getRuntime().exec("ssh -t -o ProxyCommand ssh
pp.waitFor();
BufferedReader br = new BufferedReader(new
InputStreamReader(pp.getInputStream()));
String line = "";
while ((line = br.readLine()) != null) {
System.out.println("line :"+line);
result.add(line);
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
It doest not work and does not print any thing on the console.
Do you have an idea ?
------------------------------------------------------------------------------
_______________________________________________
JSch-users mailing list
https://lists.sourceforge.net/lists/listinfo/jsch-users
Loading...