我看過php documentation中的例子,我也遇到了同樣的錯誤(我在使用WAMP的窗口中)。
一些周圍挖掘後,我發現我可以解決省略了目錄和env PARAMS的問題,例如 - 這對我的作品:
<?php
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "error-output.txt", "a") // stderr is a file to write to
);
$cwd = 'D:/wamp/www/test';
$env = array('some_option' => 'aeiou');
$process = proc_open('php', $descriptorspec, $pipes, /* $cwd, $env */);
if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to /tmp/error-output.txt
fwrite($pipes[0], '<?php print_r($_ENV); ?>');
fclose($pipes[0]);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
?>
所以,你可以嘗試更新您的代碼:
$process = proc_open($cmd, $descriptorspec, $pipes, dirname($this->getJar()));
要:
$process = proc_open($cmd, $descriptorspec, $pipes);
如果這對你有用,那麼問題出在你的代碼的這一行dirname($this->getJar())
。這個路徑不存在或者它不可訪問。
你做了var_dump()
dirname($this->getJar())
並檢查路徑是否存在?
上面的例子是固定通過設置當前工作目錄這樣也:
$process = proc_open('php', $descriptorspec, $pipes, getcwd(), $env);
根據文檔:
CWD
該命令的初始工作DIR 。如果你想使用默認值(當前PHP程序的工作目錄)
我這裏有同樣的問題在我結束 –
有什麼在$這必須是一個絕對目錄路徑,或 NULL CMD? –
請查看http://readlist.com/lists/lists.php.net/php-windows/0/798.html –