0

所以我有一个在 Eclipse 中使用 sphinx 语音识别制作的 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文件?谢谢

4

2 回答 2

0

我对此不确定,但至少尝试一次此解决方案。

尝试将 .bat 文件路径指定为C:\\c.bat,然后重试。

于 2012-05-14T06:32:51.673 回答
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

于 2012-05-14T06:41:58.330 回答