我正在尝试使用proc_open(需要双向支持)调用C++/python文件。Proc_open()C++/python
做一些在线的研究,我发现创建此代码后:(我先用C++试了一下,失败后我试图蟒蛇一样)
PHP:
<?php
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "error-output.txt", "a")
);
$process = proc_open('new.exe', $descriptorspec, $pipes);
$input = 20;
$exp = 2;
if (is_resource($process)) {
print fgets($pipes[1]);
fwrite($pipes[0], $input);
print fgets($pipes[1]);
fwrite($pipes[0], $exp);
print fgets($pipes[1]);
fclose($pipes[1]);
fclose($pipes[0]);
$return_value = proc_close($process);
echo "command returned $return_value\n";
} else {
echo "No resource availeble";
}
?>
C++:
#include <iostream>
using namespace std;
int main() {
// Get variables from php
cout << "input" << endl;
cin << input
cout << "exponent" << endl;
cin << exp
// Process variables
int answer = input + exp;
// Return variables
cout << answer;
// End c++ script
return 0;
}
的Python:
print 'enter input'
inp = raw_input()
print 'enter exponent'
exp = raw_input()
ant = inp + exp
print ant
但遗憾的是,它仍然以相同的错误失败:文件不被识别为内部或外部命令,程序或批处理文件。
一些额外的信息:
我使用WAMP与PHP 5.3.0 返回值,我从proc_close()
= 1
你编译C++程序? – 2010-10-30 14:32:21