shell_exec阻止线程不继续执行windows中的下一个语句


shell_exec blocking the thread not proceeding to next statements in windows

am正在执行如下shell命令。

shell_exec('java -jar sanityTest.jar');
$success = array('status' => "Success",'type' => "execute");
echo json_encode($success);

shell_exec命令在执行完成之前不会转到下一个语句。我想要的是在后台执行它,即使对于Windows也是如此。

我试过

shell_exec('java -jar sanityTest.jar >/dev/null 2>/dev/null &');

其正在到达下一行但不执行该命令。

我的解决方案:使用start /B *my command*

function execInBackground($cmd) { 
  if (substr(php_uname(), 0, 7) == "Windows"){ 
    pclose(popen("start /B ". $cmd, "r")); 
  } else { 
    exec($cmd . " > /dev/null &"); 
  } 
}

我可以通过查看正确的关键字找到它:https://stackoverflow.com/a/21031259/6019417