Skip to content

Commit

Permalink
Added passthru streaming example
Browse files Browse the repository at this point in the history
  • Loading branch information
kamermans committed Aug 11, 2016
1 parent 04ac844 commit 5c247db
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/stdin_streaming_stdout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use kamermans\Command\Command;

require_once __DIR__.'/../vendor/autoload.php';

$filename = __DIR__.'/../README.md';
$stdin = fopen($filename, 'r');

// This will read README.md and grep for lines containing 'the'
$cmd = Command::factory("grep 'the'")
->setCallback(function($pipe, $data) {
// Change the text to uppercase
$data = strtoupper($data);

if ($pipe === Command::STDERR) {
Command::echoStdErr($data);
} else {
echo $data;
}
})
->run($stdin);

fclose($stdin);

0 comments on commit 5c247db

Please sign in to comment.