I need to send the values of some variables from a Python script to a program "a.exe" written on C. To understand, the source of "a.exe" is here:
#include <stdio.h>
int main(){
double x1,x2;
scanf("%lf %lf", &x1, &x2);
printf("%lf+%lf=%lf", x1,x2,x1+x2);
return 0;
}
The only thing I managed to find is to send the keyboard input, not variables:
import subprocess
p = subprocess.Popen("a.exe", stdout=subprocess.PIPE)
print ( p.stdout.read() )
That script works but I need to send to "a.exe" the values of variables xx1,xx2 instead. The script should look something like this:
import subprocess
xx1=1.;xx2=2.
p = subprocess.Popen("a.exe", stdout=subprocess.PIPE)
############
it seems that there must exist a very simple solution. What to put instead of the line with ############ (or what to do in fact) so as it worked?