我正在使用Stanford命名空间但是在Stanford Tagger.php中有这个警告
警告:proc_open():CreateProcess失败,错误代码为-0
这是由这一行引起的
$process = proc_open($cmd, $descriptorspec, $pipes, dirname($this->getJar()));
我不知道如何解决它。
答案 0 :(得分:0)
我查看了php documentation中的示例,我也得到了完全相同的错误(我在使用WAMP的Windows上)。
经过一番挖掘,我发现我可以通过省略dir和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
命令的初始工作目录。这必须是绝对目录路径,或 如果要使用默认值(当前PHP进程的工作目录),则为NULL