When using $this->response->setErrorCode(..) in a console controller, after returning a string for output or a ConsoleModel, errorCode is set to "null" in meta response message.
Property $response is not really usable.
@bouchery is this still a problem?
When yes: could you please provide an example?
vote to close, Zend\Console\Response::setErrorCode() must have been replaced by setErrorLevel() (at least in 2.2.5).
ping @bouchery ...
Currently, with ZF 2.2.5, in my action, this code :
return "An error";
It displayed "An error" in my console, but shell "echo $?" return ... "0", not "-15"
I've figured out why. At some point, we introduced Zend\Mvc\ResponseSender\ConsoleResponseSender, and, at that time, deprecated the usage of Zend\Console\Response::send() — as in, we no longer call it. That method had an exit($errorLevel) call in it which was responsible for setting the exit status code; the "new" response sender does not call exit.
To get the behavior you want, you need to use Zend\View\Model\ConsoleModel:
// Inside your console action method; make sure you import the class!
$output = new ConsoleModel();
This works correctly. One note: most shells will not deal with negative numbers for statuses, and will instead subtract that number for the maximum status; -15 becomes 241.