2017-01-11 19:24:02 +01:00
|
|
|
<?php
|
|
|
|
|
2018-10-15 06:16:09 +02:00
|
|
|
include \dirname(__DIR__) . "/vendor/autoload.php";
|
2017-01-11 19:24:02 +01:00
|
|
|
|
2018-10-15 16:55:15 +02:00
|
|
|
use Amp\ByteStream;
|
2017-06-15 19:52:07 +02:00
|
|
|
use Amp\Process\Process;
|
2017-01-11 19:24:02 +01:00
|
|
|
|
2017-06-15 19:11:38 +02:00
|
|
|
Amp\Loop::run(function () {
|
2017-09-17 19:07:13 +02:00
|
|
|
if (DIRECTORY_SEPARATOR === "\\") {
|
|
|
|
echo "This example doesn't work on Windows." . PHP_EOL;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
$process = new Process('read; echo "$REPLY"');
|
2018-10-15 16:55:15 +02:00
|
|
|
yield $process->start();
|
2017-01-11 19:24:02 +01:00
|
|
|
|
|
|
|
/* send to stdin */
|
2017-06-15 19:52:07 +02:00
|
|
|
$process->getStdin()->write("abc\n");
|
2017-01-11 19:24:02 +01:00
|
|
|
|
2018-10-15 16:55:15 +02:00
|
|
|
echo yield ByteStream\buffer($process->getStdout());
|
2017-01-11 19:24:02 +01:00
|
|
|
|
2017-06-15 19:02:50 +02:00
|
|
|
$code = yield $process->join();
|
2017-01-15 16:30:34 +01:00
|
|
|
echo "Process exited with {$code}.\n";
|
2017-03-16 16:04:52 +01:00
|
|
|
});
|