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>";
?>

参见

集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。