当前位置:网站首页>PHP的exec函数
PHP的exec函数
2022-06-29 02:23:00 【hello php】
代码如下:
<?php
$out = ['a'=>'apple','b'=>'banana','c'=>'cat','d'=>'dog'];
$shell_return=null;
$v = exec('netstat -tnlp',$out,$shell_return);
print_r($out);
var_dump($shell_return);
var_dump($v);
执行后的输出如下:
Array
(
[a] => apple
[b] => banana
[c] => cat
[d] => dog
[0] => Active Internet connections (only servers)
[1] => Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
[2] => tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
[3] => tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 7311/dnsmasq
[4] => tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6987/sshd
[5] => tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 6978/cupsd
[6] => tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 16181/sshd: [email protected]
[7] => tcp6 0 0 :::3306 :::* LISTEN 7361/mysqld
[8] => tcp6 0 0 :::111 :::* LISTEN 1/systemd
[9] => tcp6 0 0 :::8080 :::* LISTEN 7689/httpd
[10] => tcp6 0 0 :::80 :::* LISTEN 7689/httpd
[11] => tcp6 0 0 :::22 :::* LISTEN 6987/sshd
[12] => tcp6 0 0 ::1:631 :::* LISTEN 6978/cupsd
[13] => tcp6 0 0 ::1:6011 :::* LISTEN 16181/sshd: [email protected]
[14] => tcp6 0 0 :::8000 :::* LISTEN 7689/httpd
)
int(0)
string(90) "tcp6 0 0 :::8000 :::* LISTEN 7689/httpd"
结论:
exec($shell, $output, $shell_return)
- $shell: shell命令, 如: 'netstat -tnlp'
- $output: 执行shell命令后的输出结果, 注意: 如果$output之前有值, 在将输出的数据追加到原来的数据之后
- $shell_return: shell命令的执行结果, 如果执行成功,返回0, 失败为其他值
- exec函数执行后的返回值: 返回$output数组的最后一条数据
边栏推荐
- Google Borg paper
- [redis] data introduction & General Command & string type
- Qt基础教程:数据类型与容器
- 东方财富股票开户是会有什么风险吗?东方财富开户安全吗
- String output
- Examen final de troisième année
- How to become a senior digital IC Design Engineer (6-7) digital IC Verification: debug skills
- 扁平结构转换为树结构
- Troubleshooting of pyinstaller failed to pack pikepdf
- e.target与e.currentTarget的区别
猜你喜欢

Boost the digital economy and face the future office | the launch of the new version of spreadjsv15.0 is about to begin

干货丨微服务架构是什么?有哪些优点和不足?
![[redis] list type](/img/c7/adec2aaea50d69a0aed95bfe683b9e.png)
[redis] list type

Koa 快速入門

What is Mipi

Learning Tai Chi Maker - mqtt Chapter II (IX) test of this chapter

对补wasm环境的一些测试

Interviewer: with the for loop, why do you need foreach??

CTFHub-Web-密码口令-弱口令
![[redis] key hierarchy](/img/ab/a5d3bb61b4571966d0f47037af4f41.png)
[redis] key hierarchy
随机推荐
大智慧手机股票开户哪个券商更安全更方便?
瀑布型项目管理最常用的10个小工具,可以自由搭建使用
Cross border information station
2022.02.15
11-Go基础:接口
110. simple chat room 13: chat room server
Com3529 test analysis
组合数据类型之元组小练习
[high concurrency, high performance and high availability of massive data MySQL practice-10] - Implementation of mvcc in InnoDB
Junior final exam
Project R & D, what are the free brain mapping tools that are easy to use
KOA Quick Start
table通过伪类实现 另类自适应
如何成为一名高级数字 IC 设计工程师(6-4)数字 IC 验证篇:测试点分解
Day10 enumeration class and annotation
Koa 快速入门
计算矩形面积
String substitution
110. 简易聊天室13:聊天室服务端
哪个证券公司最大最安全 哪家券商服务好