JAVA:Runtime.getRuntime().exec()系统找不到指定的文件

JAVA:Runtime.getRuntime().exec()系统找不到指定的文件,java,Java,我有一个exe文件:TVRRun.exe,位于目录C:\Program Files x86\TeleVantage\Client\Reporter中 我正在尝试从java代码运行该exe文件: public static void runTVRRun() throws IOException { String path = System.getenv("programfiles(x86)") + "\\TeleVantage\\Client\\Reporter\\"; Strin

我有一个exe文件:TVRRun.exe,位于目录C:\Program Files x86\TeleVantage\Client\Reporter中

我正在尝试从java代码运行该exe文件:

public static void runTVRRun() throws IOException {
    String path = System.getenv("programfiles(x86)") + "\\TeleVantage\\Client\\Reporter\\";
    String[] command = {"TVRRun.exe", "-S", templatePath, "-S", tmpReportPath};
    Runtime.getRuntime().exec(command, null, new File(path));
}
但我得到了以下错误:

Exception in thread "main" java.io.IOException: 
Cannot run program "TVRRun.exe" (in directory "C:\Program Files (x86)\TeleVantage\Client\Reporter"): 
CreateProcess error=2, The system cannot find the file specified

我尝试了exec函数的所有变体,也尝试了ProcessBuilder,但出现了相同的错误。

检查env变量我认为您在文件x86之间留出了空间,这不是问题所在。如果我从错误中复制位置,文件将运行。我甚至创建了一个运行exe文件的bat文件。通过手动运行bat文件,它运行,从java运行bat,bat运行,但是exe没有。路径中的文件名在哪里文件名是:TVRRun.exeno我是说您正在创建Instance of file,但没有指定仅指定路径的文件名,因此请尝试使用字符串path=System.getenvprogramfilesx86+\\TeleVantage\\Client\\Reporter\\TVRRun.exe;