popen

popen

(PHP 4, PHP 5)

popen打开进程文件指针

说明

resource popen ( string $command , string $mode )

打开一个指向进程的管道,该进程由派生给定的 command 命令执行而产生。

返回一个和 fopen() 所返回的相同的文件指针,只不过它是单向的(只能用于读或写)并且必须用 pclose() 来关闭。此指针可以用于 fgets()fgetss()fwrite()

如果出错返回 FALSE

Note:

如果需要双向支持,使用 proc_open()

Example #1 popen() 例子

<?php
$handle 
popen("/bin/ls""r");
?>

Note:

如果未找到要执行的命令,会返回一个合法的资源。这看上去很怪,但有道理。它允许访问 shell 返回的任何错误信息: <?php
error_reporting
(E_ALL);


$handle popen('/path/to/spooge 2>&1''r');
echo 
"'$handle'; " gettype($handle) . " ";
$read fread($handle2096);
echo 
$read;
pclose($handle);
?>

Note: 安全模式 启用时,可仅可用 safe_mode_exec_dir 执行文件。实际上,现在不允许在到可执行的路径中存在 .. 组件。

Warning

安全模式 启用时,命令字符串会被 escapeshellcmd() 转换。因此, echo y | echo x 会变成 echo y | echo x

参见 pclose()fopen()proc_open()


  • basename
  • chgrp
  • chmod
  • chown
  • clearstatcache
  • copy
  • delete
  • dirname
  • diskfreespace
  • disk_free_space
  • disk_total_space
  • fclose
  • feof
  • fflush
  • fgetc
  • fgetcsv
  • fgets
  • fgetss
  • file
  • fileatime
  • filectime
  • filegroup
  • fileinode
  • filemtime
  • fileowner
  • fileperms
  • filesize
  • filetype
  • file_exists
  • file_get_contents
  • file_put_contents
  • flock
  • fnmatch
  • fopen
  • fpassthru
  • fputcsv
  • fputs
  • fread
  • fscanf
  • fseek
  • fstat
  • ftell
  • ftruncate
  • fwrite
  • glob
  • is_dir
  • is_executable
  • is_file
  • is_link
  • is_readable
  • is_uploaded_file
  • is_writable
  • is_writeable
  • lchgrp
  • lchown
  • link
  • linkinfo
  • lstat
  • mkdir
  • move_uploaded_file
  • parse_ini_file
  • parse_ini_string
  • pathinfo
  • pclose
  • popen
  • readfile
  • readlink
  • realpath
  • realpath_cache_get
  • realpath_cache_size
  • rename
  • rewind
  • rmdir
  • set_file_buffer
  • stat
  • symlink
  • tempnam
  • tmpfile
  • touch
  • umask
  • unlink
  • PHP MySQL HTML CSS JavaScript MSSQL AJAX .NET JSP Linux Mac ASP 服务器 SQL jQuery C# C++ java Android IOS oracle MongoDB SQLite wamp 交通频道