Skip to content

Commit 5c247db

Browse files
committed
Added passthru streaming example
1 parent 04ac844 commit 5c247db

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

examples/stdin_streaming_stdout.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
use kamermans\Command\Command;
4+
5+
require_once __DIR__.'/../vendor/autoload.php';
6+
7+
$filename = __DIR__.'/../README.md';
8+
$stdin = fopen($filename, 'r');
9+
10+
// This will read README.md and grep for lines containing 'the'
11+
$cmd = Command::factory("grep 'the'")
12+
->setCallback(function($pipe, $data) {
13+
// Change the text to uppercase
14+
$data = strtoupper($data);
15+
16+
if ($pipe === Command::STDERR) {
17+
Command::echoStdErr($data);
18+
} else {
19+
echo $data;
20+
}
21+
})
22+
->run($stdin);
23+
24+
fclose($stdin);

0 commit comments

Comments
 (0)