【发布时间】:2014-05-16 14:10:59
【问题描述】:
我有两个不同的 python 可执行程序,它们在其应用程序中引用图片或 .txt 文件。当我按原样打开它们时,它们可以正常工作。我有一个在 Java 中使用的主程序,通过单击执行按钮来打开应用程序:
final String filePath = appList.get(1).get(3);//a string of the file directory
try {
Runtime.getRuntime().exec(filePath);
} catch (IOException e) {
System.err.println("Caught IOException: " + e.getMessage());
}
当我从这个主程序启动程序时,即使目录保持不变,它也无法再找到这些文件。唯一似乎改变的是,我是从 java 程序启动应用程序,而不是仅仅单击应用程序本身。有人知道该怎么做吗?
编辑: 我正在尝试:
String fileDir = appList.get(2).get(3).substring(0,appList.get(2).get(3).lastIndexOf("\\"))+"\\";
Process p = null;
ProcessBuilder pb = new ProcessBuilder(lastWord);
pb.directory(new File(fileDir));
p = pb.start();
但是system cannot find the file specified。
【问题讨论】:
标签: java runtime.exec