我正在嘗試使用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