proc_open不在简单的C程序上写入STDIN


proc_open not writing to STDIN on simple C program

下面是使用proc_open运行程序(test.exe-代码在末尾)的php脚本。它只是挂在浏览器中。测试程序没有将这两个文件写入目录。但是,如果我去掉stream_get_contents行,并在写入STDIN后将其添加进去,它会回显STDOUT。但这两个文件都没有写,我不明白为什么。有什么建议吗?编辑:echo fgetc($pipes[1]);不阻止。。。hmm

<?
test(234);
function test($number) {
  $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","whatever.log", "a") // stderr is a file to write to
  );
    $process = proc_open("cd '"C:/'" && test.exe", $descriptorspec, $pipes);
if (is_resource($process)) {
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
fwrite($pipes[0],$number);
fclose($pipes[0]);
    return !$return_value;
  }
}
?>

C程序(根据cmdline的预期工作):

#include<stdio.h>
void main()
{
int i;
FILE *ofp;
printf("Please enter an integer number");
fflush ( stdout );
scanf("%d", &i);
ofp = fopen("test.txt", "w");
fprintf(ofp, "%d", i);
fclose(ofp);
}

计算得出:你需要为窗口上的freads指定缓冲区,它似乎是:

echo fread($pipes[1], 1024);