0

我正在尝试使用proc_open()函数运行进程。正如页面上指定的 - 我提供了自定义环境变量并尝试打印出来。它显示了我提供的所有变量 + 总是 3 个变量:'SHVLL'、'PWD'、'_='。我只想打印/使用我提供的环境变量。这 3 个总是与此功能一起出现吗?有没有办法只提供变量?这一切都在 Linux 和 PHP5 下。

//Here is the code to clarify : 
$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", "/tmp/error-output.txt", "a") // stderr is a file to write to
);

$env = array('MY_VAR' => 'FOO');

$process = proc_open('./run.php', $descriptorspec, $pipes, $cwd, $env);

if (is_resource($process)) {

fwrite($pipes[0], escapeshellcmd($args));
fclose($pipes[0]);

$output = "";
while (!feof($pipes[1])) {
    $output .= fgets($pipes[1]);
}

print "Output is $output \n";
    fclose($pipes[1]);
    $return_value = proc_close($process);

}

谢谢。

4

3 回答 3

0

您可以命名您的环境变量,例如,PHP_MYVAR而不是MYVAR. 这样您就可以根据公共前缀进行过滤PHP_

于 2012-04-30T05:00:20.567 回答
0

这三个变量是由 shell 创建的。如果您不打开外壳,则不会创建它们。

于 2012-04-30T05:02:14.850 回答
0

它只是与Linux有关。它可以在 Solaris 下正常工作。我添加了正则表达式过滤器来删除那些额外的变量。

于 2012-04-30T22:59:46.480 回答