我正在尝试使用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);
}
谢谢。