当前位置: 代码迷 >> 综合 >> Java使用ProcessBuilder创建子进程出现错误:CreateProcess error=87
  详细解决方案

Java使用ProcessBuilder创建子进程出现错误:CreateProcess error=87

热度:15   发布时间:2023-12-14 21:46:56.0

 

Exception occurred executing command line. 
Cannot run program... CreateProcess error=87, The parameter is incorrect



网上说的错误原因是CLASSPATH过长,但我测试发现,还有一种原因


根据ProcessBuilder的构造器,

 

/**
Constructs a process builder with the specified operating system program and arguments. This is a convenience constructor that sets the process builder's command to a string list containing the same strings as the command array, in the same order. It is not checked whether command corresponds to a valid operating system command.Parameters:
command a string array containing the program and its arguments
**/
public ProcessBuilder(String... command) {
}



对于command参数,首个参数是命令,如果使用的是相对路径,该命令还会从操作系统的PATH环境变量中去搜寻。
如果默认不是.bat或者.exe后缀,比如(.cmd),那么需要显示加上后

  相关解决方案