When we use proc_open
in PHP:
<?php
$descriptors = array(
array('pipe', 'r'),
array('pipe', 'w'),
array('pipe', 'w'),
);
$cmd = 'cat <(ls)';
//$cmd = 'ls';
echo $cmd . PHP_EOL;
$ph = proc_open($cmd, $descriptors, $pipes);
echo stream_get_contents($pipes[1]);
echo stream_get_contents($pipes[2]);
proc_close($ph);
When run this script, an error occurred:
$ php test.php
cat <(ls)
sh: 1: Syntax error: "(" unexpected
but run the raw cmd:
$ cat <(ls)
clusterRegions.php
composer.json
composer.lock
cvCells.php
kent
prepareForTF.php
README.txt
scoreRegions.php
test.php
tests
vendor
Seems that the <()
thing cannot be recognized by proc_open
.
So how to pass a bash command with a file descriptor to proc_open
?
@Etan Reisner, you are right, when I change to bash
, it runs well.
$cmd = 'bash -c "cat <(ls)"';