php中的proc_open+fwrite应用问题
我想在php用proc_open调用一个c++写的exe程序,由于里面有要求输入参数所以我用fwrite写入终端,php代码如下
c++代码如下
上面的c++是简化的代码
(1)问题是我的c++中代码是个while循环要求持续的输入
问php中应该怎么写,现在的的php中只能fwrite($pipes[0], "q");,其它的就不行
(2)上面那段程序到能正常打印
r:q
command returned -3
我在另一个非常复杂的cpp程序去始终打印如下:
r:
command returned -1073741515
后来我在main中把其他的代码都注释掉直接复复制上面简单的c++代码到我的工程中结果还是上面的,这是我最纳闷的地方,有人遇到过么
求教高人,万分感谢
<?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", "error-output.txt", "a") // stderr is a file to write to
);
$process = proc_open("d:\\64test.exe", $descriptorspec, $pipes);
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/error-output.txt
fwrite($pipes[0], "q");
fclose($pipes[0]);
while (!feof($pipes[1]))
{
$result = fgets($pipes[1], 1024);
echo "r:$result<br>";
}
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<br>";
}
?>c++代码如下
#include <iostream>
using namespace std;
int main(int argc,char *argv[])
{
char buf[1024]={0};
/*fgets(buf,sizeof(buf),stdin);*/
while(buf[0]!='q')
{
std::cin>>buf;
std::cout<<buf;
}
return -3;
}上面的c++是简化的代码
(1)问题是我的c++中代码是个while循环要求持续的输入
问php中应该怎么写,现在的的php中只能fwrite($pipes[0], "q");,其它的就不行
(2)上面那段程序到能正常打印
r:q
command returned -3
我在另一个非常复杂的cpp程序去始终打印如下:
r:
command returned -1073741515
后来我在main中把其他的代码都注释掉直接复复制上面简单的c++代码到我的工程中结果还是上面的,这是我最纳闷的地方,有人遇到过么
求教高人,万分感谢
...全文
相关推荐
php多任务程序实例解析
主要介绍了php多任务程序实例,需要的朋友可以参考下
用PHP调用Python程序,实用且非常容易地集成到你的PHP项目中。-php-python.zip
用PHP调用Python程序,实用且非常容易地集成到你的PHP项目中。-php-python
php+html5多进程实现超大附件无刷新上传
php+html5多进程实现超大附件无刷新上传,支持超大文件,核心原理是前端将文件分割成多个片段,然后依次将片段上传到服务器,服务器后端接收到全部片段后,再组装成完整的文件,已经测试可以正常上传。
PHP实现执行外部程序的方法详解
本文实例讲述了PHP实现执行外部程序的方法。分享给大家供大家参考,具体如下: 在一些特殊情况下,会使用PHP调用外部程序执行,比如:调用shell命令、shell脚本、可执行程序等等,今天在源码中了解了一下PHP执行外部程序的方法,借此机会顺便整理一下。 在源码中 exec.h文件中,列出了可调用外部程序的几个函数,蓝色框里的两个函数只是辅助作用,本文只对其他几个函数做介绍。 前提 1 PHP没有运行在安全模式,关掉安全模式,即:safe_mode = off 2 禁用函数列表 disable_functions = exec, system, shell_exec,proc_open,
php后门木马常用命令.pdf
php后门木马常用命令.pdf


基础编程
