我有以下的測試代碼:當我經過的ArrayList到的ProcessBuilder我得到的沒有這樣的文件或目錄錯誤
public class TestProcessBuilder {
public static void main(String args[]) {
String imageLocation = "/home/john/image";
String installCommand = "java -jar install.jar -install /home/john/install.properties";
ProcessBuilder pb = new ProcessBuilder();
pb.directory(new File(imageLocation));
pb.command(Arrays.asList(installCommand.split("\\+s")));
try {
pb.start();
} catch(Exception e) {
e.printStackTrace();
System.out.println("Failed to run command");
}
}
這給了我一個錯誤:
Cannot run program "java -jar install.jar -install /home/john/install.properties" (in directory "/home/john/"): error=2, No such file or directory
我一定要創建一個單獨的列表,然後手動將每個標記化的項目添加到它。我認爲這應該工作...
我也曾嘗試:'列表 list2 = new ArrayList ();對於(String s:Arrays.asList(installCommand.split(「\\ + s」))){ list2.add(s); } pb.command(list2); ' –
eeijlar