1

我想从 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);

它不工作,任何帮助将不胜感激。 这个命令需要从java中执行

4

2 回答 2

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());
于 2016-07-13T12:32:41.830 回答
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();
于 2016-07-13T12:29:40.260 回答