PHP 中的 popen() 函数
phpprogrammingserver side programming更新于 2025/8/31 4:22:17
popen() 函数打开一个管道。它可以与 fgets()、fgetss() 和 fwrite() 一起使用。popen() 函数启动的文件指针必须使用 pclose() 关闭。
语法
popen(command, mode)
参数
command − 设置要执行的命令
mode − 设置模式,例如 “r”、“w” 等。
返回
popen() 函数成功时返回 TRUE。如果发生错误,则返回 FALSE。
示例
<?php
// 打开管道
$file_pointer = popen("/bin/ls", "r");
pclose($file_pointer);
?>
输出
TRUE
让我们看另一个例子。
示例
<?php
// opening a pipe
$file_pointer = popen("/executable/installer.exe", "r");
pclose($file_pointer);
?>
输出
TRUE

