php中的proc_open+fwrite应用有关问题
Jun 13, 2016 am 10:50 AM
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>";}?>
Nach dem Login kopieren
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>
Nach dem Login kopieren
上面的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"); 试试看
------解决方案--------------------
啥意思?
他让你将逐次输出的数据组装成串后一次性输出
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heißer Artikel
Wie lange dauert es, um Split Fiction zu schlagen?
3 Wochen vor
By DDD
Repo: Wie man Teamkollegen wiederbelebt
3 Wochen vor
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Abenteuer: Wie man riesige Samen bekommt
3 Wochen vor
By 尊渡假赌尊渡假赌尊渡假赌
Zwei -Punkte -Museum: Alle Exponate und wo man sie finden kann
3 Wochen vor
By 尊渡假赌尊渡假赌尊渡假赌

Hot-Tools-Tags

Heißer Artikel
Wie lange dauert es, um Split Fiction zu schlagen?
3 Wochen vor
By DDD
Repo: Wie man Teamkollegen wiederbelebt
3 Wochen vor
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Abenteuer: Wie man riesige Samen bekommt
3 Wochen vor
By 尊渡假赌尊渡假赌尊渡假赌
Zwei -Punkte -Museum: Alle Exponate und wo man sie finden kann
3 Wochen vor
By 尊渡假赌尊渡假赌尊渡假赌

Heiße Artikel -Tags

Notepad++7.3.1
Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version
Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6
Visuelle Webentwicklungstools

SublimeText3 Mac-Version
Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Heiße Themen

PHP 8.4 Installations- und Upgrade-Anleitung für Ubuntu und Debian

So richten Sie Visual Studio-Code (VS-Code) für die PHP-Entwicklung ein
