Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP proc_open返回值始终等于127_Php - Fatal编程技术网

PHP proc_open返回值始终等于127

PHP proc_open返回值始终等于127,php,Php,我在PHP方面面临着一个非常大的问题我正在创建PHP应用程序,它将“使用”另一个应用程序。我想重定向输入和输出。我正在使用proc\u open这样做文件gsqasm在/var/www/http内,工作目录相同,因此/gsqasm应该可以实现这一点。太糟糕了,它没有返回代码始终等于127。在谷歌搜索了一段时间后,我发现127意味着找不到该文件。然后,为了确保,我检查了/tmp/error output.txt文件。它的内容是: sh: 1: gsqasm: not found sh: 1: /v

我在PHP方面面临着一个非常大的问题我正在创建PHP应用程序,它将“使用”另一个应用程序。我想重定向输入和输出。我正在使用
proc\u open
这样做文件
gsqasm
/var/www/http
内,工作目录相同,因此
/gsqasm
应该可以实现这一点。太糟糕了,它没有返回代码始终等于127。在谷歌搜索了一段时间后,我发现127意味着找不到该文件。然后,为了确保,我检查了
/tmp/error output.txt
文件。它的内容是:

sh: 1: gsqasm: not found
sh: 1: /var/www/http/gsqasm: not found
sh: 1: /var/www/http/gsqasm: not found
sh: 1: /var/www/http/gsqasm: not found
sh: 1: ./gsqasm: not found
sh: 1: ./gsqasm: not found
sh: 1: .gsqasm: not found
sh: 1: /var/www/http/gsqasm: not found
sh: 1: /var/www/http/gsqasm: not found
正如你所看到的,我试过很多次,运气都不好。我很可能错过了一些明显的东西,但我想不出来。这是我的密码:

<?php
$descriptorspec = array(
    0 => array(
        "pipe",
        "r"
    ), // stdin is a pipe that the child will read from
    1 => array(
        "pipe",
        "w"
    ), // stdout is a pipe that the child will write to
    2 => array(
        "file",
        "/tmp/error-output.txt",
        "a"
    ) // stderr is a file to write to
);

$cwd = '/tmp';
$env = array(
    'some_option' => 'aeiou'
);

passthru('echo $PWD');
echo '<br>';
$process = proc_open('./gsqasm', $descriptorspec, $pipes, $cwd, $env);

if (!isset($_POST['input'])) {
    echo "Input is empty.";
}

if (is_resource($process)) {
    // $pipes now looks like this:
    // 0 => writeable handle connected to child stdin
    // 1 => readable handle connected to child stdout
    // Any error output will be appended to /tmp/erroroutput.txt

    fwrite($pipes[0], $_POST['input']);
    fclose($pipes[0]);

    echo stream_get_contents($pipes[1]);
    fclose($pipes[1]);

    // It is important that you close any pipes before calling
    // proc_close in order to avoid a deadlock
    $return_value = proc_close($process);

    echo "command returned $return_value\n";
}
?>


在重定向流时,如何更改此代码以正确执行应用程序?这不是为在生产环境中运行而设计的代码,它是一些快速而肮脏的东西,在一段时间后会变得稳定。

退出代码127实际上意味着“找不到命令”。该文件可能存在于
/var/www/http/gsqasm
,但您让它查看
/tmp/gsqasm
。您将运行命令的工作目录
$cwd
,设置为
/tmp
。该命令的前面还有
/
,告诉它在(错误提供的)当前工作目录中查找
gsqasm


要解决此问题,您可以将
$cwd
更改为
null
(请参阅,这默认为脚本的目录)或程序位置的绝对路径,您所说的路径也是
/var/www/http
。您还可以更改
/
以包含该绝对路径。这三个选项中的任何一个都会起作用,我个人推荐第一个,因为它很简单。

退出代码127实际上意味着“找不到命令”。该文件可能存在于
/var/www/http/gsqasm
,但您让它查看
/tmp/gsqasm
。您将运行命令的工作目录
$cwd
,设置为
/tmp
。该命令的前面还有
/
,告诉它在(错误提供的)当前工作目录中查找
gsqasm


要解决此问题,您可以将
$cwd
更改为
null
(请参阅,这默认为脚本的目录)或程序位置的绝对路径,您所说的路径也是
/var/www/http
。您还可以更改
/
以包含该绝对路径。这三个选项中的任何一个都可以,我个人推荐第一个,因为它简单。

gsqasm计划的所有权和权限是什么?你能在你的问题中提供这一点吗?
ls-lathF | grep gsqasm
-rwxr-xr-x 1 root 88K Mar 25 07:07 gsqasm*是输出。在你刚刚运行ls的同一目录中,请运行
pwd
并提供输出gsqasm程序的所有权和权限是什么?你能在你的问题中提供这一点吗?
ls-lathF | grep gsqasm
-rwxr-xr-x 1 root 88K Mar 25 07:07 gsqasm*是输出。在你刚才运行ls的同一个目录中,请运行
pwd
,并提供你可以在日志中看到的输出,我试图使用绝对路径,但运气不佳。CWD与此有什么关系…?正如您在日志中所看到的,我试图使用绝对路径,但运气不佳。CWD和这有什么关系。。。?