run.shスクリプトを実行する必要がある次のJavaコードがあります。run.shがプロセスビルダーで実行されていません
public void executeScript() {
try {
Process p = null;
ProcessBuilder pb = new ProcessBuilder("phoneManagement/src/run.sh");
//pb.directory(new File("phoneManagement/src"));
p = pb.start(); // Start the process.
p.waitFor(); // Wait for the process to finish.
System.out.println("Script executed successfully");
} catch (Exception e) {
e.printStackTrace();
}
}
そしてrun.sh次のようになります。
#!/bin/sh
javac -cp ".:../../selenium/selenium-java-2.53.1.jar:../../selenium/selenium-server-standalone-2.53.1.jar:../../selenium/libs/*" phoneManagement.java
java -cp ".:../../selenium/selenium-java-2.53.1.jar:../../selenium/selenium-server-standalone-2.53.1.jar:../../selenium/libs/*" phoneManagement
私は、コマンドラインから.SHスクリプトを実行すると、それはそれは、私のphoneManagementコンパイルして実行されるべきものありません。
私のexecuteScriptクラスを使用すると、run.shは必要な処理を実行していないのに、「Script executed successfully」というメッセージが表示されます。
誰でも私にこれを助けることができますか?
ありがとう
完全パスを使用してください。コマンドが失敗する可能性は高いですが、例外が出るとは思いません。コマンドから出力を出力してみてください。 – 123