我想使用Java和ProcessBuilder運行腳本。當我嘗試運行時,我收到以下消息:錯誤= 2,沒有這樣的文件或目錄。使用ProcessBuilder運行shell腳本
我不知道我做錯了,但這裏是我的代碼(PS:我試着不帶參數只執行腳本和錯誤是一樣的:
String[] command = {"/teste/teste_back/script.sh, "+argument1+", "+argument+""};
ProcessBuilder p = new ProcessBuilder(command);
try {
// create a process builder to send a command and a argument
Process p2 = p.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p2.getInputStream()));
String line;
log.info("Output of running " + command + " is: ");
System.out.println("Output of running " + command + " is: ");
while ((line = br.readLine()) != null) {
log.info(line);
}
}
的([的ProcessBuilder和的Runtime.exec()之間的不同]可能的複製https://stackoverflow.com/questions/6856028/process-process-and-runtime-exec之間的差異) – Steephen