我试图运行使用proc_open()函数的进程。正如在页面上指定的那样 - 我提供了自定义环境变量并试图打印出来。它显示了我提供的所有变量+总是3个变量:'SHLVL','PWD','_ ='。我想打印/只使用我提供的环境变量。这3个功能总是存在吗?有没有办法只提供变量?这全部在Linux和PHP5下。PHP proc_open环境变量
//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);
}
谢谢。
我不明白你为什么*要*打开一个shell,但如果你做*然后就没有办法绕过它。 –
那...不......在任何地方调用shell ... –
而且?它仍然不会在任何地方调用shell。 –