php执行外部命令

阿紫 posted @ 2012年8月30日 12:08 in php , 1452 阅读

这几天在做一个域名解析的东东,要在php中调用系统命令,就整理一下。

一、使用exec()函数执行系统外部命令:
原型:function exec(string $command,array[optional] $output,int[optional] $return_value)
例:exec("nslookup $s1 $s2",$result,$output);//执行nslookup命令

  exec执行系统外部命令时不会输出结果,而是返回结果的最后一行,如果想得到结果可以使用第二个参数,将结果输出到指定的数组,数组一个记录代表输出的一行,第三个参数是取得命令执行的状态码,执行成功返回0.

二、使用system函数执行系统外部命令:

 

原型:function system(string $command,int[optional] $return_value)
例:system("nslookup $s1 $s2");

三、使用函数passthru执行外部命令:

 

原型:function passthru(string $command,int[optional] $return_value)

 

与system的区别是,passthru直接将结果输出到浏览器,但是不返回任何值,且可以输出二进制。
 
四、反撇号(`)执行外部命令:
    使用该命令时要确保shell_exec函数可用。
  • 无匹配
seo service UK 说:
2024年2月24日 16:55

My Future Consulting is a top ranked employment agency and diversity/ executive search firm in Chicago, Illinois that consistently delivers top rated talent.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter