我的 php 代码可执行文件('ls -l') 不会 ls 所有文件



我有一个/Users/dele/Desktop/TestIOS/testPhp01/cms/test04.php文件:

<?php
/**
* Created by PhpStorm.
* User: dele
* Date: 2019/9/26
* Time: 11:56 AM
*/
exec("ls -l");

当我运行此文件时,只显示一个文件输出,

/usr/local/Cellar/php@7.0/7.0.30_1/bin/php /Users/dele/Desktop/TestIOS/testPhp01/cms/test04.php
string(54) "-rw-r--r--  1 dele  staff   133 Oct  8 12:03 test04.php"
Process finished with exit code 0

但是在我的目录/Users/dele/Desktop/TestIOS/testPhp01/cms/中,有这些文件:

dele-MBP:cms ldl$ ls -l
total 48
-rw-r--r--  1 ldl  staff     0 Aug 20 16:49 1
-rw-r--r--  1 ldl  staff    42 Aug 20 16:49 2.js
-rw-r--r--  1 ldl  staff   165 Feb 18  2019 index.php
-rw-r--r--  1 ldl  staff   551 Aug 30 17:36 test01.php
-rw-r--r--  1 ldl  staff  1308 Sep  8 00:38 test02.php
-rw-r--r--  1 ldl  staff  1444 Sep 10 23:09 test03.php
-rw-r--r--  1 ldl  staff   107 Oct  8 11:56 test04.php

尝试使用输出参数:

exec("ls -l", $r);
var_dump($r);
<?php
exec("ls -l", $items, $return_status);
foreach ($items as $key => $item) {
printf("%sn", $item);
}

执行文档

最新更新