linux php shell exec,PHP shell_exec()vs exec()

这是差异。请注意最后的换行符。

> shell_exec('date')

string(29) "Wed Mar  6 14:18:08 PST 2013\n"

> exec('date')

string(28) "Wed Mar  6 14:18:12 PST 2013"

> shell_exec('whoami')

string(9) "mark\n"

> exec('whoami')

string(8) "mark"

> shell_exec('ifconfig')

string(1244) "eth0      Link encap:Ethernet  HWaddr 10:bf:44:44:22:33  \n          inet addr:192.168.0.90  Bcast:192.168.0.255  Mask:255.255.255.0\n          inet6 addr: fe80::12bf:ffff:eeee:2222/64 Scope:Link\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\n          RX packets:16264200 errors:0 dropped:1 overruns:0 frame:0\n          TX packets:7205647 errors:0 dropped:0 overruns:0 carrier:0\n          collisions:0 txqueuelen:1000 \n          RX bytes:13151177627 (13.1 GB)  TX bytes:2779457335 (2.7 GB)\n"...

> exec('ifconfig')

string(0) ""

更新:我真的应该解释最后一个。几年后看这个答案,即使我不知道为什么会出现空白!丹尼尔在上面解释了 - 这是因为exec只返回最后一行,而ifconfig最后一行恰好是空白。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值