Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82e5552

Browse files
committed
merged branch Tobion/console-status-code (PR #8202)
This PR was merged into the 2.1 branch. Discussion ---------- [Console] fix status and exit code Fix #8183 (comment) and http://www.php.net/manual/en/function.exit.php > Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully. Commits ------- 6b9180a [Console] ensure exit code between 0-254 445b2e3 [Console] fix status code when Exception::getCode returns something like 0.1
2 parents 28a9001 + 6b9180a commit 82e5552

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,22 @@ public function run(InputInterface $input = null, OutputInterface $output = null
113113
} else {
114114
$this->renderException($e, $output);
115115
}
116-
$statusCode = $e->getCode();
117116

118-
$statusCode = is_numeric($statusCode) && $statusCode ? (int) $statusCode : 1;
117+
$statusCode = $e->getCode();
118+
if (is_numeric($statusCode)) {
119+
$statusCode = (int) $statusCode;
120+
if (0 === $statusCode) {
121+
$statusCode = 1;
122+
}
123+
} else {
124+
$statusCode = 1;
125+
}
119126
}
120127

121128
if ($this->autoExit) {
122-
if ($statusCode > 255) {
123-
$statusCode = 255;
124-
}
129+
// ensure exit code is between 0-254 (255 is reserved by PHP and should not be used)
125130
// @codeCoverageIgnoreStart
126-
exit($statusCode);
131+
exit(max(0, min(254, $statusCode)));
127132
// @codeCoverageIgnoreEnd
128133
}
129134

0 commit comments

Comments
 (0)