dsb0003795 2012-09-13 12:42
浏览 173
已采纳

使用未定义的常量STDOUT - 假设为“STDOUT”

I am running the following proc_open function. When the page is loaded, I get the error:

Use of undefined constant STDOUT - assumed 'STDOUT'`

How should I set STDOUT and STSDERR correctly?

PHP Snippet

$cmd = 'psql -p 5432 -d nominatim';

$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => STDOUT,  // stdout is a pipe that the child will write to
   2 => STDERR // stderr is a file to write to
);

$pipes = null;

$process = proc_open($cmd, $descriptorspec, $pipes);

Update

<?php

    $cmd = 'psql -p 5432 -d nominatim';

    $descriptorspec = array(
        0 => array('pipe', 'r'), // stdin
        1 => array('pipe', 'w'), // stdout
        2 => array('pipe', 'a') // stderr
    );

    $pipes = null;

    $process = proc_open($cmd, $descriptorspec, $pipes);

?>

When I chmod 755 test.php and run ./test.php in the command line (CentOS), I get the error output:

: No such file or directory
: command not found
./test.php: line 3: =: command not found
: command not found
: command not found
./test.php: line 5: syntax error near unexpected token `('
'/test.php: line 5: `   $descriptorspec = array(

This is puzzling, = is not a command?


Update 2

#!/usr/bin/php <?php

    $cmd = 'psql -p 5432 -d nominatim';

    $descriptorspec = array(
        0 => array('pipe', 'r'), // stdin
        1 => array('pipe', 'w'), // stdout
        2 => array('pipe', 'a') // stderr
    );

    $pipes = null;

    $process = proc_open($cmd, $descriptorspec, $pipes);

?>

I get the output:

Status: 404 Not Found
X-Powered-By: PHP/5.3.16
Content-type: text/html

No input file specified.
  • 写回答

1条回答 默认 最新

  • douqu8828 2012-09-13 12:49
    关注

    You may use :

    $descriptorspec = array(
        0 => array('pipe', 'r'), // stdin
        1 => array('pipe', 'w'), // stdout
        2 => array('pipe', 'a') // stderr
    );
    

    instead

    Have a look to the manual

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答