gpt4 book ai didi

php - 使用未定义常量 STDOUT - 假定为 'STDOUT'

转载 作者:行者123 更新时间:2023-11-29 13:35:45 35 4
gpt4 key购买 nike

我正在运行以下 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.

最佳答案

你可以使用:

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

代替

查看 manual

关于php - 使用未定义常量 STDOUT - 假定为 'STDOUT',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12406549/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com