我的术语不适用,但这里是:
假设一个执行:
/bin/一些命令
在 php 中使用 exec 或 system
以上命令返回'exit code'(这是可能关闭的术语)'1'。
是否可以通过 php 获取此值?
如果可能,请在不使用“父”bash 脚本的情况下执行此操作。我们希望能够直接从 php 获取它,而不必运行父 bash 脚本,并让该脚本回显退出代码。
谢谢!
最佳答案
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; ?>
关于php - 在 php 中通过 exec/system 执行时获取 linux 命令退出代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6483317/