找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 669|回复: 0

[LINUX] PHP 命令运行函数

[复制链接]

3

主题

1

回帖

15

积分

新手上路

积分
15
发表于 2023-6-15 15:45:16 | 显示全部楼层 |阅读模式
1、exec函数

  1. <?php
  2.   $test = "ls /tmp/test";   //ls是linux下的查目录,文件的命令
  3.   exec($test,$array);       //执行命令
  4.   print_r($array);
  5. ?>
复制代码
2、system函数


  1. <?php
  2.   $test = "ls /tmp/test";
  3.   $last = system($test);
  4.   print "last: $last\n";
  5. ?>
复制代码
3、passthru函数


  1. <?php
  2.   $test = "ls /tmp/test";
  3.   passthru($test);
  4. ?>
复制代码
4、popen函数


  1. <?php
  2.   $test = "ls /tmp/test";
  3.   $fp = popen($test,"r");  //popen打一个进程通道
  4.   while (!feof($fp)) {      //从通道里面取得东西
  5.     $out = fgets($fp, 4096);
  6.     echo  $out;         //打印出来
  7.   }
  8.   pclose($fp);
  9. ?>
复制代码
5、proc_open函数


  1. <?php
  2.   $test = "ls /tmp/test";
  3.   $arrayarray =   array(
  4.     array("pipe","r"),   //标准输入
  5.     array("pipe","w"),   //标准输出内容
  6.     array("pipe","w")    //标准输出错误
  7.   );
  8.   $fp = proc_open($test,$array,$pipes);   //打开一个进程通道
  9.   echo stream_get_contents($pipes[1]);    //为什么是$pipes[1],因为1是输出内容
  10.   proc_close($fp);
  11. ?>
复制代码
6、proc_open函数


  1. <?php
  2.   $test = "ls /tmp/test";
  3.   $arrayarray =   array(
  4.     array("pipe","r"),   //标准输入
  5.     array("pipe","w"),   //标准输出内容
  6.     array("pipe","w")    //标准输出错误
  7.   );
  8.   $fp = proc_open($test,$array,$pipes);   //打开一个进程通道
  9.   echo stream_get_contents($pipes[1]);    //为什么是$pipes[1],因为1是输出内容
  10.   proc_close($fp);
  11. ?>
复制代码
7、shell_exec函数


  1. <?php
  2.   $test = "ls /tmp/test";
  3.   $out = shell_exec($test);
  4.   echo $out;
  5. ?>
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|魅力松滋 ( 鄂ICP备2024076975号-1 )

GMT+8, 2025-5-7 00:09 , Processed in 0.092317 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表