1
0
mirror of https://github.com/danog/process.git synced 2024-12-04 02:27:49 +01:00
process/example/watch-live.php

20 lines
441 B
PHP
Raw Normal View History

<?php
include dirname(__DIR__) . "/vendor/autoload.php";
2017-01-15 16:30:34 +01:00
use Amp\Process\StreamedProcess;
Amp\Loop::run(function() {
$process = new StreamedProcess("echo 1; sleep 1; echo 2; sleep 1; echo 3; exit 42");
2017-01-15 16:30:34 +01:00
$promise = $process->execute();
2017-01-15 16:30:34 +01:00
$stdout = $process->getStdout();
2017-01-15 16:30:34 +01:00
while (yield $stdout->advance()) {
echo $stdout->getCurrent();
}
2017-01-15 16:30:34 +01:00
$code = yield $promise;
echo "Process exited with {$code}.\n";
});