【发布时间】:2015-11-24 04:35:11
【问题描述】:
当我们在 PHP 中使用proc_open 时:
<?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);
运行此脚本时发生错误:
$ php test.php
cat <(ls)
sh: 1: Syntax error: "(" unexpected
但运行原始 cmd:
$ cat <(ls)
clusterRegions.php
composer.json
composer.lock
cvCells.php
kent
prepareForTF.php
README.txt
scoreRegions.php
test.php
tests
vendor
似乎<() 无法被proc_open 识别。
那么如何将带有文件描述符的 bash 命令传递给 proc_open 呢?
【问题讨论】:
-
proc_open和朋友们几乎可以肯定默认使用/bin/sh。在许多系统上哪个不支持进程替换。您可以查看是否可以通过配置或其他方式让proc_open使用/bin/bash,或者您可以在proc_open调用中手动运行bash。