bash - Can you trigger a specific exit status on a php fatal error? -
i've tried following:
<?php function shutdown_find_exit() { exit(50); } register_shutdown_function('shutdown_find_exit'); trigger_error("fatal error", e_user_error); ?> but still exists error code of 255.
i'm trying have error code of 50 returned.
i'm checking following bash script:
php tester.php status=$? echo exit code: ${status} updated code based on accepted answer interested:
<?php function shutdown_find_exit() { exit('50'); } register_shutdown_function('shutdown_find_exit'); trigger_error("fatal error", e_user_error); ?> and bash script
output="$(php tester.php)" status=$? echo exit code: ${status} if [[ $output == *"50"* ]] echo "got 50"; fi
tl;dr: use string, instead of int.
if status string, function prints status before exiting.
if status integer, value used exit status , not printed. exit statuses should in range 0 254, exit status 255 reserved php , shall not used. status 0 used terminate program successfully.
note: php >= 4.2.0 not print status if integer.
execute php script in bash, assign output variable.
variable = $(/path/to/php -f $home/path/to/my.php) for example:
# executing php, capturing output then, prints console status = $(/usr/bin/php -f $home/path/to/tester.php) echo exit code: ${status} hope helps.
Comments
Post a Comment