【问题标题】:How to Disable the output of command in php如何在php中禁用命令的输出
【发布时间】:2013-09-13 14:48:48
【问题描述】:
system("echo $new_password | sudo -u root passwd --stdin $username");

我正在使用此代码更改 PHP 中的密码。但它在网页上显示以下输出:

Changing password for user abcd@xyz.com. passwd: all authentication tokens updated successfully.

如何禁用此输出?

【问题讨论】:

    标签: php linux command output


    【解决方案1】:

    你也可以重定向它

    system("echo $new_password | sudo -u root passwd --stdin $username") 3>/dev/null
    

    这会将标准输出发送到 null。虽然如果有任何东西通过不同的方式进入(例如 stderr),你必须单独重定向它。

    【讨论】:

      【解决方案2】:

      使用 exec 而不是 system

      <?php
       exec("echo $new_password | sudo -u root passwd --stdin $username");
      ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-13
        相关资源
        最近更新 更多