【问题标题】:My php code exec('ls -l') do not ls all files我的 php 代码 exec('ls -l') 不 ls 所有文件
【发布时间】:2019-10-08 03:59:44
【问题描述】:

我有一个/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

【问题讨论】:

    标签: php exec ls


    【解决方案1】:

    尝试使用输出参数:

    exec("ls -l", $r);
    var_dump($r);
    

    【讨论】:

      【解决方案2】:
      <?php
      
      exec("ls -l", $items, $return_status);
      
      foreach ($items as $key => $item) {
        printf("%s\n", $item);
      }
      

      Exec documentation

      【讨论】:

        猜你喜欢
        • 2017-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-11
        • 1970-01-01
        • 2011-01-30
        • 2015-02-05
        相关资源
        最近更新 更多