-
Couldn't load subscription status.
- Fork 53
Support the ability to output to console while the command getting executed #56
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,12 @@ class Command | |
| */ | ||
| public $escapeArgs = true; | ||
|
|
||
| /** | ||
| * @var bool whether to stream the output of current command getting executed | ||
| * Default is `false`. | ||
| */ | ||
| public $streamOutput = false; | ||
|
|
||
| /** | ||
| * @var bool whether to escape the command passed to `setCommand()` or the | ||
| * constructor. This is only useful if `$escapeArgs` is `false`. Default | ||
|
|
@@ -469,9 +475,13 @@ public function execute() | |
| // | ||
| while (($out = fgets($pipes[1])) !== false) { | ||
| $this->_stdOut .= $out; | ||
| if($this->streamOutput) | ||
| echo $out; | ||
| } | ||
| while (($err = fgets($pipes[2])) !== false) { | ||
| $this->_stdErr .= $err; | ||
| if($this->streamOutput) | ||
| echo $err; | ||
| } | ||
|
|
||
| $runTime = $hasTimeout ? time() - $startTime : 0; | ||
|
|
@@ -511,6 +521,18 @@ public function execute() | |
| } | ||
| fclose($pipes[0]); | ||
| } | ||
|
|
||
| if($this->streamOutput) | ||
| { | ||
| while(!feof($pipes[1])) | ||
| { | ||
| $return_message = fgets($pipes[1], 1024); | ||
| if (strlen($return_message) == 0) break; | ||
|
|
||
| echo $return_message; | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block would not work as expected: In blocking mode, this part is not reached until the command ist complete. If we want to introduce such a feature it only makes sense for |
||
|
|
||
| $this->_stdOut = stream_get_contents($pipes[1]); | ||
| $this->_stdErr = stream_get_contents($pipes[2]); | ||
| fclose($pipes[1]); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes that there's always a console (tty) connected. But this may not always be the case. Echoing out here also limits the way this feature can be used. It would be much more flexible if we would accept a stream here (e.g.
STDOUT,STDERR, ...). This would be similar to what we do withstdIn. So a better way would probably be, to addsetStdOutStream()andsetStdErrStream()and then write to the streams here and below.As this change is not so trivial and there's already a lot going on here, we need to test that nothing breaks.
I can maybe try to implement it that way - but can't promise yet if I find time soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.