Bash 陷阱命令未能捕捉到致命的 php 脚本退出代码 255
Bash trap command failing to catch fatal php script exit code 255
问题的最小示例:
#!/bin/bash
errHandler() {
echo "Something went wrong. Exiting now."
exit 1
}
trap 'errHandler' ERR INT
pi_process () {
bin/pi $@
echo $?
}
pi_process stuff
bin/pi 是一个 php 脚本,它正在退出,退出代码为 255 并出现致命错误。但是 bash 陷阱没有被捕获。怎么会?
set -o functrace
似乎没有达到您的预期。
试试这个:
#! /bin/bash
set -e
errHandler() {
echo "Something went wrong. Exiting now."
exit 1
}
trap 'errHandler' EXIT
pi_process () {
false
echo $?
}
pi_process stuff
问题的最小示例:
#!/bin/bash
errHandler() {
echo "Something went wrong. Exiting now."
exit 1
}
trap 'errHandler' ERR INT
pi_process () {
bin/pi $@
echo $?
}
pi_process stuff
bin/pi 是一个 php 脚本,它正在退出,退出代码为 255 并出现致命错误。但是 bash 陷阱没有被捕获。怎么会?
set -o functrace
似乎没有达到您的预期。
试试这个:
#! /bin/bash
set -e
errHandler() {
echo "Something went wrong. Exiting now."
exit 1
}
trap 'errHandler' EXIT
pi_process () {
false
echo $?
}
pi_process stuff