Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Echoing forked process output to stdout on demand #14

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ class Command
*/
protected $_executed = false;

/**
* @var bool whether process output should be echoed directly to stdout
*/
protected $echoOutput = false;

/**
* @param string|array $options either a command string or an options array (see setOptions())
*/
Expand Down Expand Up @@ -306,7 +311,17 @@ public function execute()

if (is_resource($process)) {

$this->_stdOut = stream_get_contents($pipes[1]);
if ($this->echoOutput) {
$this->_stdOut = "";
while (!feof($pipes[1])) {
$fragment = fgets($pipes[1]);
$this->_stdOut .= $fragment;
echo($fragment);
}
} else {
$this->_stdOut = stream_get_contents($pipes[1]);
}

$this->_stdErr = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
Expand Down