【问题标题】:shell_exec blocking the thread not proceeding to next statements in windowsshell_exec 阻止线程不继续执行 windows 中的下一个语句
【发布时间】:2016-08-03 06:22:28
【问题描述】:

正在执行如下所示的 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 &');

即将进入下一行但未执行命令。

【问题讨论】:

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

标签: php windows shell shell-exec


【解决方案1】:

我的解决方案:使用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

【讨论】:

    猜你喜欢
    • 2015-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-12
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    相关资源
    最近更新 更多