(PHP 4, PHP 5, PHP 7)
popen — 锟津开斤拷锟斤拷锟侥硷拷指锟斤拷
$command
, string $mode
) : resource锟斤拷一锟斤拷指锟斤拷锟斤拷痰墓艿锟斤拷锟斤拷媒锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� command 锟斤拷锟斤拷执锟叫讹拷锟斤拷锟斤拷锟斤拷
command
锟斤拷锟筋。
mode
模式锟斤拷
锟斤拷锟斤拷一锟斤拷锟斤拷 fopen() 锟斤拷锟斤拷锟截碉拷锟斤拷同锟斤拷锟侥硷拷指锟诫,只锟斤拷锟斤拷锟斤拷锟角碉拷锟斤拷模锟街伙拷锟斤拷锟斤拷诙锟斤拷锟叫达拷锟斤拷锟斤拷冶锟斤拷锟斤拷锟� pclose() 锟斤拷锟截闭★拷锟斤拷指锟斤拷锟斤拷锟斤拷锟斤拷锟� fgets()锟斤拷fgetss() 锟斤拷 fwrite()锟斤拷 锟斤拷模式为 'r'锟斤拷锟斤拷锟截碉拷锟侥硷拷指锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 STDOUT锟斤拷锟斤拷模式为 'w'锟斤拷锟斤拷锟截碉拷锟侥硷拷指锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 STDIN锟斤拷
锟斤拷锟斤拷锟斤拷锟斤拷锟� FALSE
锟斤拷
Example #1 popen() 锟斤拷锟斤拷
<?php
$handle = popen("/bin/ls", "r");
?>
锟斤拷锟轿达拷业锟揭达拷械锟斤拷锟斤拷睿拷岱碉拷锟揭伙拷锟斤拷戏锟斤拷锟斤拷锟皆达拷锟斤拷饪达拷锟饺ワ拷芄郑锟斤拷锟斤拷械锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 shell 锟斤拷锟截碉拷锟轿何达拷锟斤拷锟斤拷息锟斤拷
Example #2 popen() 锟斤拷锟斤拷
<?php
error_reporting(E_ALL);
/* 锟斤拷锟斤拷锟截讹拷锟斤拷锟皆得碉拷锟斤拷准锟斤拷锟斤拷锟斤拷锟� stderr锟斤拷 */
$handle = popen('/path/to/executable 2>&1', 'r');
echo "'$handle'; " . gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;
pclose($handle);
?>
Note:
锟斤拷锟斤拷锟揭拷锟街э拷郑锟绞癸拷锟� proc_open()锟斤拷
Note: 锟斤拷全模式 锟斤拷锟斤拷时锟斤拷锟缴斤拷锟斤拷锟斤拷 safe_mode_exec_dir 执锟斤拷锟侥硷拷锟斤拷实锟斤拷锟较o拷锟斤拷锟节诧拷锟斤拷锟斤拷锟节碉拷锟斤拷执锟叫碉拷路锟斤拷锟叫达拷锟斤拷 .. 锟斤拷锟斤拷锟�
锟斤拷全模式 锟斤拷锟斤拷时锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟结被 escapeshellcmd() 转锟斤拷锟斤拷锟斤拷耍锟�echo y | echo x 锟斤拷锟斤拷 echo y \| echo x锟斤拷