What's the proper way for setting the exit status code in a Symfony2 command?
In plain php you can do this with exit(123)
. But I guess Symfony2 has an OOP way. Is that right? I couldn't find anything on the docs though.
I need this mostly because I want to be able to do something like this in Linux: app/console my:command || { echo "Something went wrong, I'm gonna call handle_disaster now"; handle_disaster; }
In the base Command
class:
if ($this->code) { $statusCode = call_user_func($this->code, $input, $output); } else { $statusCode = $this->execute($input, $output); } return is_numeric($statusCode) ? (int) $statusCode : 0;
So simply return the exit code from your execute()
function. Your console command will exit with this code as long as it is a numeric value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With