1
0
mirror of https://github.com/danog/process.git synced 2024-11-30 04:39:04 +01:00
process/examples/basic-command.php

19 lines
522 B
PHP
Raw Normal View History

<?php
include dirname(__DIR__) . "/vendor/autoload.php";
2018-07-18 23:03:51 +02:00
use Amp\ByteStream\ResourceOutputStream;
use Amp\Process\Process;
2018-07-18 23:03:51 +02:00
// "echo" is a shell internal command on Windows and doesn't work.
$command = DIRECTORY_SEPARATOR === "\\" ? "cmd /c echo Hello World!" : "echo 'Hello, world!'";
2018-07-18 23:03:51 +02:00
$process = new Process($command);
$process->start();
2018-07-18 23:03:51 +02:00
$stdout = new ResourceOutputStream(STDOUT);
Amp\ByteStream\pipe($process->getStdout(), $stdout);
2018-07-18 23:03:51 +02:00
$exitCode = $process->join();
echo "Process exited with {$exitCode}." . PHP_EOL;