我想从java程序中执行tabula工具命令。我正在尝试的代码是:
System.setProperty("user.dir", "C:\\Program Files");
String command ="\\tabula\\tabula-0.9.0-SNAPSHOT-jar-with-dependencies.jar "+"D:\\sample.pdf"+" -o "+"D:\\sampleeeee.csv";
Process p = Runtime.getRuntime().exec(command);
它不起作用,任何帮助将不胜感激。 this command need to be executed from java
答案 0 :(得分:1)
您可以在致电exec
时指定工作目录:
Path workingDir = Paths.get("C:\\Program Files\\tabula");
String[] command = {
"tabula-0.9.0-SNAPSHOT-jar-with-dependencies.jar",
"sample.pdf",
"-o samk.csv"
};
Process p = Runtime.getRuntime().exec(command, null, workingDir.toFile());
答案 1 :(得分:0)
尝试此操作以设置将运行命令的工作目录。
https://stackoverflow.com/a/8405745/1364747
Process p = null;
ProcessBuilder pb = new ProcessBuilder("java","-jar","tabula-0.9.0-SNAPSHOT-jar-with-dependencies.jar", "D:\\sample.pdf", "-o", "D:\\sampleeeee.csv");
pb.directory("C:\\Program Files\\tabula");
p = pb.start();