【问题标题】:getting linux command exit code when executed via exec/system in php在php中通过exec / system执行时获取linux命令退出代码
【发布时间】:2011-09-22 22:08:45
【问题描述】:

我的术语我是关闭的,但这里是:

假设执行:

/bin/一些命令

在 php 中使用 exec 或 system

上述命令返回“退出代码”(这是可能关闭的术语)“1”。

是否可以通过 php 获取该值?

如果可能,请不要使用“父”bash 脚本来执行此操作。我们希望能够直接从 php 获取它,而不必运行父 bash 脚本,并让该脚本回显退出代码。

谢谢!

【问题讨论】:

    标签: php linux shell system exec


    【解决方案1】:

    manual for exec() 表明您可以提供可选的第三个参数来收集返回状态(退出代码)。与system() 类似,第二个可选参数。

    该页面的示例:

    <?php
    echo '<pre>';
    
    // Outputs all the result of shellcommand "ls", and returns
    // the last output line into $last_line. Stores the return value
    // of the shell command in $retval.
    $last_line = system('ls', $retval);
    
    // Printing additional info
    echo '
    </pre>
    <hr />Last line of the output: ' . $last_line . '
    <hr />Return value: ' . $retval;
    ?>
    

    【讨论】:

    • 哇!我的坏我应该更详细地阅读这个。叹。无论如何,正确答案!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 2016-10-10
    • 1970-01-01
    • 2013-06-26
    • 2018-11-21
    • 1970-01-01
    相关资源
    最近更新 更多