10000 merged branch romainneutron/ProcessExitCode (PR #5386) · sunqipenglib/symfony@569e29d · GitHub
[go: up one dir, main page]

Skip to content

Commit 569e29d

Browse files
committed
merged branch romainneutron/ProcessExitCode (PR symfony#5386)
Commits ------- 407db65 Add @Seldaek remote modifications 3bfb976 Add unit test demonstrating bad exit code getter for a failing process Discussion ---------- Add unit test demonstrating bad exit code getter for a failing process Since symfony/symfony@7b63428698 exit code are not well handled anymore. The unit test provided with this PR demonstrates it --------------------------------------------------------------------------- by fabpot at 2012-08-30T11:05:05Z ping @Seldaek --------------------------------------------------------------------------- by stof at 2012-08-30T11:13:13Z We probably need to enable the workaround only when sigchild is used. --------------------------------------------------------------------------- by Seldaek at 2012-08-30T12:51:22Z Ok I figured out the problem, the hack is even hackier I guess now, but it should work for people with and without --enable-sigchild at least.
2 parents 2982e6e + 407db65 commit 569e29d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function start($callback = null)
218218
array('pipe', 'w'), // stderr
219219
array('pipe', 'w') // last exit code is output on the fourth pipe and caught to work around --enable-sigchild
220220
);
221-
$this->commandline = '('.$this->commandline.') 3>/dev/null; echo $? >&3';
221+
$this->commandline = '('.$this->commandline.') 3>/dev/null; code=$?; echo $code >&3; exit $code';
222222
}
223223

224224
$commandline = $this->commandline;

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ public function testCallbackIsExecutedForOutput()
8989
$this->assertTrue($called, 'The callback should be executed with the output');
9090
}
9191

92+
public function testExitCodeCommandFailed()
93+
{
94+
if (strpos(PHP_OS, "WIN") === 0) {
95+
$this->markTestSkipped('Windows does not support POSIX exit code');
96+
}
97+
98+
// such command run in bash return an exitcode 127
99+
$process = new Process('nonexistingcommandIhopeneversomeonewouldnameacommandlikethis');
100+
$process->run();
101+
102+
$this->assertGreaterThan(0, $process->getExitCode());
103+
}
104+
92105
public function testExitCodeText()
93106
{
94107
$process = new Process('');

0 commit comments

Comments
 (0)
0