shell_exec 通过 shell 环境执行命令,并且将完整的输出以字符串的方式返回。
发表日期:2021-07-01 08:56:11 | 来源: | | 浏览(447) 分类:程序执行函数
shell_exec
(PHP 4, PHP 5, PHP 7, PHP 8)
shell_exec — 通过 shell 环境执行命令,并且将完整的输出以字符串的方式返回。
说明
shell_exec(string
$cmd
): string本函数同 执行操作符。
注意:
On Windows, the underlying pipe is opened in text mode which can cause the function to fail for binary output. Consider to use popen() instead for such cases.
参数
-
cmd
-
要执行的命令。
返回值
命令执行的输出。
如果执行过程中发生错误或者进程不产生输出,则返回 null
。
注意:
当进程执行过程中发生错误,或者进程不产生输出的情况下,都会返回
null
, 所以,使用本函数无法通过返回值检测进程是否成功执行。 如果需要检查进程执行的退出码,请使用 exec() 函数。
范例
示例 #1 shell_exec() 例程
<?php $output = shell_exec('ls -lart'); echo "<pre>$output</pre>"; ?>
- PHP(0)
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- escapeshellarg 把字符串转码为可以在 shell 命令里使用的参数(0)
- escapeshellcmd shell 元字符转义(0)
- exec 执行一个外部程序(0)
- passthru 执行外部程序并且显示原始输出(0)
- proc_close 关闭由 proc_open() 打开的进程并且返回进程退出码(0)
- proc_get_status 获取由 proc_open() 函数打开的进程的信息(0)
- proc_nice 修改当前进程的优先级(0)
- proc_open 执行一个命令,并且打开用来输入/输出的文件指针。(0)
- proc_terminate 杀除由 proc_open 打开的进程(0)
- shell_exec 通过 shell 环境执行命令,并且将完整的输出以字符串的方式返回。(0)
- system 执行外部程序,并且显示输出(0)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- 杂项 函数(31)
- 字符串 函数(101)