2

I have a script in amazon machine and i would run this script using ssh from netbeans. i use this code :

String myKey="/home/local/my_key.pem";
Runtime runtime = Runtime.getRuntime();
String commande = "ssh -i "+myKey+" [email protected] 'bash runFile.bash' -o StrictHostKeyChecking=no ";

Process p = runtime.exec(commande);
p.waitFor();

But it does not work. When i print p.getErrorStream() I obtain:

bash: writeFile.bash: command not found

When i run the commande from bash it works but in netbeans no !

Someone can explain me why ? other solution please ?

Thanks

12
  • What do you get? an error message? can you add it to the question? Commented Mar 4, 2014 at 14:59
  • No error, just the command line does not make what it should do ! Commented Mar 4, 2014 at 15:01
  • 1
    what is returned? you can also read p's getOutputStream() and getErrorStream() to see if you can see what the problems may be Commented Mar 4, 2014 at 15:22
  • 1
    and... is there a ~/local/my_key.pem? Commented Mar 4, 2014 at 15:29
  • 1
    What is writeFile.bash? is it a file you are trying to execute? is it where it is supposed to be? is it executable? try executing ./writeFile.bash Commented Mar 4, 2014 at 15:40

1 Answer 1

1

Try this:

String myKey="/home/local/my_key.pem";
Runtime runtime = Runtime.getRuntime();
String commande = "ssh -i "+myKey+" [email protected] 'bash ./runFile.bash' -o StrictHostKeyChecking=no ";

Process p = runtime.exec(commande);
p.waitFor();

(use bash ./runFile.bash instead of bash runFile.bash)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.