我在亚马逊机器上有一个脚本,我会使用netbeans中的ssh运行这个脚本。 我使用这段代码:
String myKey="/home/local/my_key.pem";
Runtime runtime = Runtime.getRuntime();
String commande = "ssh -i "+myKey+" ubuntu@ec2-53-71-22-288.eu-west-1.compute.amazonaws.com 'bash runFile.bash' -o StrictHostKeyChecking=no ";
Process p = runtime.exec(commande);
p.waitFor();
但它不起作用。当我打印p.getErrorStream()
时,我获得了:
bash: writeFile.bash: command not found
当我从commande
运行bash
时,它可以运行,但是在netbeans中没有!
有人能解释我为什么吗?请问其他解决方案
由于
答案 0 :(得分:1)
试试这个:
String myKey="/home/local/my_key.pem";
Runtime runtime = Runtime.getRuntime();
String commande = "ssh -i "+myKey+" ubuntu@ec2-53-71-22-288.eu-west-1.compute.amazonaws.com 'bash ./runFile.bash' -o StrictHostKeyChecking=no ";
Process p = runtime.exec(commande);
p.waitFor();
(使用bash ./runFile.bash
代替bash runFile.bash
)