当使用PHP Exec方法时,如何知道Shell Scitpt成功执行

发布于 2025-01-29 09:17:41 字数 74 浏览 2 评论 0原文

我正在使用PHP中的EXEC运行shell脚本,EXEC已成功执行并给出0作为结果代码。是否有任何方法可以成功执行所有Shell脚本?

I am running shell script using exec in php, exec is successfully executes and give 0 as result code. is there any way to check all shell script is executed successfully or not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囍孤女 2025-02-05 09:17:41

如果退出代码为零,则脚本成功运行到其目的。

退出代码HOWOVER并不意味着您的Shell脚本在内部工作,而是没有执行。每当您想声明出现问题时,返回有效的退出代码是您的Shells脚本的责任。

此外,最好用退出0表明您的脚本运行而没有错误,这是一个很好的做法。出口代码<> 0意味着这完全取决于您。

例子:

#!/usr/bin/env bash

echo "This script will always fail"

# return exitcode <> 0 to state that something went wrong
exit 1

If the exit code is zero, then the script ran successfully to it's end.

The exit code code howover does not imply that your shell script worked internally, but rather it did not fail to execute. It is your shells script's duty to return a valid exit code whenever you want to state that something went wrong.

Furthermore it is good practice to explicitly quit with exit 0 to state that your script is ran with no error. What an exit code <> 0 means it totally up to you.

Example:

#!/usr/bin/env bash

echo "This script will always fail"

# return exitcode <> 0 to state that something went wrong
exit 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文