php中的proc_open+fwrite应用有关问题
fwrite
gt
php
quot
php中的proc_open+fwrite应用问题
我想在php用proc_open调用一个c++写的exe程序,由于里面有要求输入参数所以我用fwrite写入终端,php代码如下
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?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++代码如下
- C/C++ code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#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</iostream>
登录后复制
上面的c++是简化的代码
(1)问题是我的c++中代码是个while循环要求持续的输入
问php中应该怎么写,现在的的php中只能fwrite($pipes[0], "q");,其它的就不行
(2)上面那段程序到能正常打印
r:q
command returned -3
我在另一个非常复杂的cpp程序去始终打印如下:
r:
command returned -1073741515
后来我在main中把其他的代码都注释掉直接复复制上面简单的c++代码到我的工程中结果还是上面的,这是我最纳闷的地方,有人遇到过么
求教高人,万分感谢
------解决方案--------------------
fwrite($pipes[0], "cmd1\ncmd2\ncmd3\nq"); 试试看
------解决方案--------------------
啥意思?
他让你将逐次输出的数据组装成串后一次性输出
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前
By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
击败分裂小说需要多长时间?
3 周前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保护它?
3 周前
By DDD

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PHP 8.4 带来了多项新功能、安全性改进和性能改进,同时弃用和删除了大量功能。 本指南介绍了如何在 Ubuntu、Debian 或其衍生版本上安装 PHP 8.4 或升级到 PHP 8.4

CakePHP 是 PHP 的开源框架。它的目的是使应用程序的开发、部署和维护变得更加容易。 CakePHP 基于类似 MVC 的架构,功能强大且易于掌握。模型、视图和控制器 gu

Visual Studio Code,也称为 VS Code,是一个免费的源代码编辑器 - 或集成开发环境 (IDE) - 可用于所有主要操作系统。 VS Code 拥有针对多种编程语言的大量扩展,可以轻松编写
