fix: handle stdio properly

This commit is contained in:
2025-08-17 13:55:24 +02:00
parent 4ae0545ab4
commit 5f6f5bf04b
15 changed files with 311 additions and 120 deletions

35
examples/stdio.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
use Nih\CommandBuilder\Command;
use Nih\CommandBuilder\Stdio;
require_once __DIR__ . '/../vendor/autoload.php';
$child = (new Command('cat'))
->stdin(Stdio::piped())
->stdout(Stdio::piped())
->spawn();
$child->stdin?->write('Hello, World!');
$output = $child->waitWithOutput();
var_dump($output);
// object(Nih\CommandBuilder\Output)#6 (3) {
// ["stdout"]=>
// string(13) "Hello, World!"
// ["stderr"]=>
// NULL
// ["code"]=>
// object(Nih\CommandBuilder\ExitStatus)#4 (1) {
// ["code"]=>
// int(0)
// }
// }
(new Command('echo'))
->arg('Hello, World!')
->stdout(Stdio::inherit())
->status();
// Hello, World!