Skip to content

Commit

Permalink
[Process] Added support for stdout and stderr flush (Issue #7884)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Traverso authored and fabpot committed Sep 27, 2013
1 parent ded2984 commit 90daef7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Symfony/Component/Process/Process.php
Expand Up @@ -532,6 +532,19 @@ public function getIncrementalOutput()
return $latest;
}

/**
* Clears the process output.
*
* @return Process
*/
public function flushOutput()
{
$this->stdout = '';
$this->incrementalOutputOffset = 0;

return $this;
}

/**
* Returns the current error output of the process (STDERR).
*
Expand Down Expand Up @@ -565,6 +578,19 @@ public function getIncrementalErrorOutput()
return $latest;
}

/**
* Clears the process output.
*
* @return Process
*/
public function flushErrorOutput()
{
$this->stderr = '';
$this->incrementalErrorOutputOffset = 0;

return $this;
}

/**
* Returns the exit code returned by the process.
*
Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/Process/Tests/AbstractProcessTest.php
Expand Up @@ -156,6 +156,15 @@ public function testGetIncrementalErrorOutput()
}
}

public function testFlushErrorOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));

$p->run();
$p->flushErrorOutput();
$this->assertEmpty($p->getErrorOutput());
}

public function testGetOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}')));
Expand All @@ -175,6 +184,15 @@ public function testGetIncrementalOutput()
}
}

public function testFlushOutput()
{
$p = new Process(sprintf('php -r %s', escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}')));

$p->run();
$p->flushOutput();
$this->assertEmpty($p->getOutput());
}

public function testExitCodeCommandFailed()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
Expand Down

0 comments on commit 90daef7

Please sign in to comment.