mirror of
https://github.com/danog/process.git
synced 2024-12-13 01:27:26 +01:00
Fix examples and running on Unix
This commit is contained in:
parent
624d8b59de
commit
7117a6aa92
@ -6,7 +6,8 @@ use Amp\ByteStream\Message;
|
||||
use Amp\Process\Process;
|
||||
|
||||
Amp\Loop::run(function () {
|
||||
$process = yield Process::start("echo 'Hello, world!'");
|
||||
$process = new Process("echo 'Hello, world!'");
|
||||
$process->start();
|
||||
|
||||
echo yield new Message($process->getStdout());
|
||||
|
||||
|
@ -6,11 +6,8 @@ use Amp\Process\Process;
|
||||
use Amp\Promise;
|
||||
use function Amp\Promise\all;
|
||||
|
||||
function show_process_output(Promise $promise): \Generator
|
||||
function show_process_output(Process $process): \Generator
|
||||
{
|
||||
/** @var Process $process */
|
||||
$process = yield $promise;
|
||||
|
||||
$stream = $process->getStdout();
|
||||
while ($chunk = yield $stream->read()) {
|
||||
echo $chunk;
|
||||
@ -27,7 +24,9 @@ Amp\Loop::run(function () {
|
||||
$promises = [];
|
||||
|
||||
foreach ($hosts as $host) {
|
||||
$promises[] = new \Amp\Coroutine(show_process_output(Process::start("ping {$host}")));
|
||||
$process = new Process("ping {$host}");
|
||||
$process->start();
|
||||
$promises[] = new \Amp\Coroutine(show_process_output($process));
|
||||
}
|
||||
|
||||
yield all($promises);
|
||||
|
@ -5,10 +5,11 @@ include dirname(__DIR__) . "/vendor/autoload.php";
|
||||
use Amp\Process\Process;
|
||||
|
||||
Amp\Loop::run(function () {
|
||||
$process = yield Process::start("echo 1; sleep 1; echo 2; sleep 1; echo 3; exit 42");
|
||||
$process = new Process("echo 1; sleep 1; echo 2; sleep 1; echo 3; exit 42");
|
||||
$process->start();
|
||||
|
||||
$stream = $process->getStdout();
|
||||
while ($chunk = yield $stream->read()) {
|
||||
while (null !== $chunk = yield $stream->read()) {
|
||||
echo $chunk;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,8 @@ use Amp\ByteStream\Message;
|
||||
use Amp\Process\Process;
|
||||
|
||||
Amp\Loop::run(function () {
|
||||
$process = yield Process::start('read ; echo "$REPLY"');
|
||||
$process = new Process('read ; echo "$REPLY"');
|
||||
$process->start();
|
||||
|
||||
/* send to stdin */
|
||||
$process->getStdin()->write("abc\n");
|
||||
|
@ -24,6 +24,7 @@ final class Runner implements ProcessRunner {
|
||||
|
||||
public static function onProcessEndExtraDataPipeReadable($watcher, $stream, Handle $handle) {
|
||||
Loop::cancel($watcher);
|
||||
$handle->extraDataPipeWatcher = null;
|
||||
|
||||
$handle->status = ProcessStatus::ENDED;
|
||||
|
||||
|
@ -200,7 +200,7 @@ class Process {
|
||||
* @return ProcessOutputStream
|
||||
*/
|
||||
public function getStdin(): ProcessOutputStream {
|
||||
return $this->stdin;
|
||||
return $this->handle->stdin;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -213,7 +213,7 @@ class Process {
|
||||
throw new StatusError("The process is not running");
|
||||
}
|
||||
|
||||
return $this->stdout;
|
||||
return $this->handle->stdout;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -226,7 +226,7 @@ class Process {
|
||||
throw new StatusError("The process is not running");
|
||||
}
|
||||
|
||||
return $this->stderr;
|
||||
return $this->handle->stderr;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user