Java-->;CreateProcess错误=2,系统找不到指定的文件

Java-->;CreateProcess错误=2,系统找不到指定的文件,java,processbuilder,Java,Processbuilder,我面临以下错误: java.io.IOException: Cannot run program "C:\abc\man\b\manu.bat C:\Users\12x\test\testFiles\abc.properties" (in directory "C:\Users\12x\test\testFiles\abc.properties"): CreateProcess error=2, The system cannot find the file specified at j

我面临以下错误:

java.io.IOException: Cannot run program "C:\abc\man\b\manu.bat C:\Users\12x\test\testFiles\abc.properties" (in directory "C:\Users\12x\test\testFiles\abc.properties"): CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048).
请查找我正在使用的代码:

public class TestProcess {


public TestProcess(Path workPath, Path exe, Path logbackConfig, 
                     Path propertyfile) throws IOException {

    String exeSuffix = "";
    if (OS.indexOf("win") >= 0) {
      exeSuffix = ".bat";
    }
    builder = new ProcessBuilder()
            .directory(workPath.toFile())

            .command(workPath.resolve(exe).toAbsolutePath().toString() + exeSuffix+ " " + propertyfile)
            .redirectOutput(Redirect.INHERIT)
            .redirectError(Redirect.INHERIT);
我的目标是运行一个bat文件(位于C:\abc\man\b文件夹中),后跟abc.properties(位于另一个文件夹C:\Users\12x\test\testFiles中)

在上面的代码中,workPath的值为

C:\abc\man\b
而propertyfile

C:\Users\12x\test\testFiles

不能在Windows中直接使用.bat文件。您必须插入
cmd/c

您不能直接在Windows中插入.bat文件。您必须插入
cmd/c

您没有使用正确的语法:您不能将程序及其参数串联在字符串中,因为ProcessBuilder不是解析器

相反,构建一个名为propertyfile\u path\u String的字符串,该字符串对应于属性文件,并将您的行
.command(…)
替换为以下行:

.command(workPath.resolve(exe).toAbsolutePath().toString() + exeSuffix, propertyfile_path_string)

您没有使用正确的语法:因为ProcessBuilder不是解析器,所以不能将程序及其参数连接到字符串中

相反,构建一个名为propertyfile\u path\u String的字符串,该字符串对应于属性文件,并将您的行
.command(…)
替换为以下行:

.command(workPath.resolve(exe).toAbsolutePath().toString() + exeSuffix, propertyfile_path_string)

我尝试了这一点,但出现了以下错误:类型ProcessBuilder中的方法命令(List)不适用于参数(String,Path)@SandepGoyal,因此请使用
propertyfile.toString()
.yooo…工作正常…我在回答中添加了“build a String named propertyfile\u Path\u String”。我尝试了这一点,但出现了以下错误:方法命令(List)在类型中,ProcessBuilder不适用于参数(字符串,路径)@sandepgoyal,因此请使用
propertyfile.toString()
.yooo…工作正常…我在答案中添加了“构建名为propertyfile\u Path\u String的字符串”。