所以我有一个用ehin语言识别的eclipse制作的java项目。如果我说某个单词,那么它会运行一个.bat文件。
if (resultText.equals("word")) {
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("C:/c.bat");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在Eclipse中它工作正常,但在我导出.jar并运行它之后,如果我说那个特定的单词,它就不会运行.bat。所以任何想法为什么它只从eclipse而不是从命令行运行我的.bat文件?感谢
答案 0 :(得分:0)
我不确定这一点,但至少尝试一次这个解决方案。
尝试将.bat文件路径设为C:\\c.bat
,然后重试。
答案 1 :(得分:0)
尝试添加以下内容:
File f = new File("c:/c.bat");
if(f.exists()) {
// execute the file
Process process = runtime.exec(f.getAbsolutePath());
process.waitFor();
InputStream stdout = process.getInputStream();
InputStream stderr = process.getErrorStream();
// check the streams for errors
} else {
// log error
}
HTH