Firstly, sorry for my English. Is it possible to start .exe program with php script and pass input after the program has started. I can't use command line arguments.
#include <iostream>
using namespace std;
int main() {
int a, b;
cin>>a>>b;
return a+b;
}
<?php
$handle = popen('echo 1 2 | /path/to/compiled-program', 'r');
$read = fread($handle, 32);
echo $read;
pclose($handle);
?>
BTW, your c++ program does not compile.
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a + b << endl;
return 0;
}
If you only need to write to your executable stdin, use popen
: http://php.net/manual/en/function.popen.php
If you need to write to stdin and get results from stdout, use proc_open
: http://php.net/manual/en/function.proc-open.php
Yes you can there are several functions that do that