Php 具有proc_open()的多输入

Php 具有proc_open()的多输入,php,stdin,proc-open,Php,Stdin,Proc Open,我目前正在做一个在线程序。我正在编写一个php脚本,它使用proc_open()在命令行中执行命令(在Linux Ubuntu下)。这是我目前的代码: <?php $cmd = "./power"; $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"), ); $process = proc_open($cm

我目前正在做一个在线程序。我正在编写一个php脚本,它使用proc_open()在命令行中执行命令(在Linux Ubuntu下)。这是我目前的代码:

<?php
$cmd = "./power";

$descriptorspec = array(
   0 => array("pipe", "r"),
   1 => array("pipe", "w"),
   2 => array("pipe", "w"),
);

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

if (is_resource($process)) {

    fwrite($pipes[0], "4");
    fwrite($pipes[0], "5");
    fclose($pipes[0]);

    while($pdf_content = fgets($pipes[1]))
    {
        echo $pdf_content . "<br>";
    }
    fclose($pipes[1]);

    $return_value = proc_close($process);
}
?>

power是一个要求输入2次的程序(它接受一个基数和一个指数,并计算基数和指数)。它是用汇编写的。但是当我运行这个脚本时,我得到了错误的输出。我的输出为“1”,但我希望输出为4^5

当我运行一个只接受一个输入的程序时,它就工作了(我测试了一个简单的程序,它将输入的值增加一个)

我想我遗漏了一些关于fwrite命令的信息。谁能帮帮我吗


提前谢谢

你忘了给管道写换行符,所以你的程序会认为它只得到了
45
作为输入。试试这个:

fwrite($pipes[0], "4");
fwrite($pipes[0], "\n");
fwrite($pipes[0], "5");
fclose($pipes[0]);
或更短:

fwrite($pipes[0], "4\n5");
fclose($pipes[0]);

非常感谢。这就是问题所在:)