【发布时间】:2013-12-06 11:08:25
【问题描述】:
下面是使用 proc_open 运行程序(最后是 test.exe-code)的 php 脚本。
它只是挂在浏览器中。
测试程序没有将这两个文件写入目录。但是,如果我取出 stream_get_contents 行并在写入 STDIN 后添加它,它会回显 STDOUT。这两个文件都没有写,我不明白为什么。有什么建议么?
编辑:echo fgetc($pipes[1]); 不会阻止...嗯
<?
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);
}
【问题讨论】: