【问题标题】:Use of undefined constant STDOUT - assumed 'STDOUT'使用未定义的常量 STDOUT - 假定为“STDOUT”
【发布时间】:2023-03-29 03:33:01
【问题描述】:

我正在运行以下proc_open 函数。加载页面时,我收到错误:

Use of undefined constant STDOUT - assumed 'STDOUT'`

如何正确设置STDOUTSTSDERR

PHP 代码段

$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);

更新

<?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);

?>

当我 chmod 755 test.php 并在命令行 (CentOS) 中运行 ./test.php 时,我得到错误输出:

: 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(

这令人费解,=不是命令?


更新 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);

?>

我得到了输出:

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

No input file specified.

【问题讨论】:

  • 也许php://stdoutphp://stderr 会起作用?
  • 我试过了,但出现了错误fopen() [function.fopen]: Invalid php:// URL specified

标签: php apache postgresql postgresql-9.1 proc-open


【解决方案1】:

你可以使用:

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

改为

看看manual

【讨论】:

  • 我在命令行上尝试过,并用错误消息更新了原始帖子。
  • 在文件的最顶部添加 #!/usr/bin/php,或者使用 php test.php 代替输入 ./test.php
  • 不要把#!/usr/bin/php
猜你喜欢
  • 2013-07-20
  • 2012-05-19
  • 2015-07-11
  • 2014-05-07
  • 2014-04-30
  • 2013-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多