【问题标题】:php proc_open file descriptor in bash commandbash命令中的php proc_open文件描述符
【发布时间】: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

似乎&lt;() 无法被proc_open 识别。 那么如何将带有文件描述符的 bash 命令传递给 proc_open 呢?

【问题讨论】:

  • proc_open 和朋友们几乎可以肯定默认使用/bin/sh。在许多系统上哪个不支持进程替换。您可以查看是否可以通过配置或其他方式让proc_open 使用/bin/bash,或者您可以在proc_open 调用中手动运行bash

标签: php bash shell proc-open


【解决方案1】:

@Etan Reisner,你是对的,当我更改为 bash 时,它运行良好。

$cmd = 'bash -c "cat <(ls)"';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 1970-01-01
    • 2015-12-10
    • 1970-01-01
    相关资源
    最近更新 更多