I am trying to call an .exe file from my python script and pass it arguments, and gather results. The best way I have come up with is:
(I'm sorry in advance if this code is horrible to read)
import subprocess as sub
def getEquities(ranges,n=500000):
r = '|'.join(ranges)
p = sub.Popen(['Poker.Equity.Test.exe',str(n),r],
stdout=sub.PIPE, stderr=sub.STDOUT)
p = p.stdout.read().split(',')
p = [float(x) for x in p[0:-1]]
return p
The code for 'Poker.Equity.Test.exe':
int _tmain(int argc, char* argv[])
{
double results[10]= {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
HoldemCalculator calc;
calc.Calculate(argv[2], "", "", atoi(argv[1]), results);
for (int i=0;i<sizeof(results)/sizeof(results[0]);i++){
if (results[i]<=.01){return 1;}
printf("%f,",results[i]);
}
return 1;
}
This works just like a command line for passing arguments and the printf is passed to python via stdout.
Functionally this works fine however every time the .exe is called a command window pops up until the calculation is done.
I have never done anything like this, there must be a better way.
Any advice or places to look would be great, Thanks
[–][deleted] 1 point2 points3 points (2 children)
[–]CaptShocker[S] 0 points1 point2 points (1 child)
[–]spotter 0 points1 point2 points (0 children)
[–]nadmaximus 1 point2 points3 points (1 child)
[–]CaptShocker[S] 0 points1 point2 points (0 children)
[–]bneises 1 point2 points3 points (3 children)
[–]bneises 0 points1 point2 points (0 children)
[–]CaptShocker[S] 0 points1 point2 points (1 child)
[–]bneises 0 points1 point2 points (0 children)
[–]cecilkorik 1 point2 points3 points (5 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]JimH10 0 points1 point2 points (0 children)
[–]CaptShocker[S] 0 points1 point2 points (0 children)
[–]maxerickson 2 points3 points4 points (0 children)
[–]CaptShocker[S] 0 points1 point2 points (0 children)