mirror of
https://github.com/danog/process.git
synced 2024-11-29 20:29:16 +01:00
Update examples
This commit is contained in:
parent
b71e5c0544
commit
91dc2ec100
@ -5,7 +5,7 @@
|
||||
"require": {
|
||||
"php": ">=7",
|
||||
"amphp/amp": "^2",
|
||||
"amphp/byte-stream": "^1.2"
|
||||
"amphp/byte-stream": "^1.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^6",
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
include \dirname(__DIR__) . "/vendor/autoload.php";
|
||||
|
||||
use Amp\ByteStream\Message;
|
||||
use Amp\ByteStream;
|
||||
use Amp\Process\Process;
|
||||
|
||||
Amp\Loop::run(function () {
|
||||
@ -10,9 +10,9 @@ Amp\Loop::run(function () {
|
||||
$command = DIRECTORY_SEPARATOR === "\\" ? "cmd /c echo Hello World!" : "echo 'Hello, world!'";
|
||||
|
||||
$process = new Process($command);
|
||||
$process->start();
|
||||
yield $process->start();
|
||||
|
||||
echo yield new Message($process->getStdout());
|
||||
echo yield ByteStream\buffer($process->getStdout());
|
||||
|
||||
$code = yield $process->join();
|
||||
echo "Process exited with {$code}.\n";
|
||||
|
@ -7,6 +7,8 @@ use function Amp\Promise\all;
|
||||
|
||||
function show_process_output(Process $process): \Generator
|
||||
{
|
||||
yield $process->start();
|
||||
|
||||
$stream = $process->getStdout();
|
||||
|
||||
while (null !== $chunk = yield $stream->read()) {
|
||||
@ -14,7 +16,7 @@ function show_process_output(Process $process): \Generator
|
||||
}
|
||||
|
||||
$code = yield $process->join();
|
||||
$pid = yield $process->getPid();
|
||||
$pid = $process->getPid();
|
||||
|
||||
echo "Process {$pid} exited with {$code}\n";
|
||||
}
|
||||
@ -29,7 +31,6 @@ Amp\Loop::run(function () {
|
||||
? "ping -n 5 {$host}"
|
||||
: "ping -c 5 {$host}";
|
||||
$process = new Process($command);
|
||||
$process->start();
|
||||
$promises[] = new Amp\Coroutine(show_process_output($process));
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ Amp\Loop::run(function () {
|
||||
? "cmd /c echo 1 & ping -n 2 127.0.0.1 > nul & echo 2 & ping -n 2 127.0.0.1 > nul & echo 3 & exit 42"
|
||||
: "echo 1; sleep 1; echo 2; sleep 1; echo 3; exit 42";
|
||||
$process = new Process($command);
|
||||
$process->start();
|
||||
yield $process->start();
|
||||
|
||||
$stream = $process->getStdout();
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
include \dirname(__DIR__) . "/vendor/autoload.php";
|
||||
|
||||
use Amp\ByteStream\Message;
|
||||
use Amp\ByteStream;
|
||||
use Amp\Process\Process;
|
||||
|
||||
Amp\Loop::run(function () {
|
||||
@ -12,12 +12,12 @@ Amp\Loop::run(function () {
|
||||
}
|
||||
|
||||
$process = new Process('read; echo "$REPLY"');
|
||||
$process->start();
|
||||
yield $process->start();
|
||||
|
||||
/* send to stdin */
|
||||
$process->getStdin()->write("abc\n");
|
||||
|
||||
echo yield new Message($process->getStdout());
|
||||
echo yield ByteStream\buffer($process->getStdout());
|
||||
|
||||
$code = yield $process->join();
|
||||
echo "Process exited with {$code}.\n";
|
||||
|
Loading…
Reference in New Issue
Block a user