Мой PHP-код Exec ('ls -l') не все файлы - PullRequest
1 голос
/ 08 октября 2019

У меня есть /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

Ответы [ 2 ]

1 голос
/ 08 октября 2019

попробуйте использовать выходной параметр:

exec("ls -l", $r);
var_dump($r);
0 голосов
/ 08 октября 2019
<?php

exec("ls -l", $items, $return_status);

foreach ($items as $key => $item) {
  printf("%s\n", $item);
}

Exec документация

...