Running an external program inside a Do loop

*To*: mathgroup at smc.vnet.net*Subject*: [mg130458] Running an external program inside a Do loop*From*: Luiz Melo <lmelo at ufsj.edu.br>*Date*: Fri, 12 Apr 2013 02:18:05 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*Delivered-to*: l-mathgroup@wolfram.com*Delivered-to*: mathgroup-newout@smc.vnet.net*Delivered-to*: mathgroup-newsend@smc.vnet.net

Hi I have to run an external program inside a Do loop, as in the example below. The .exe program takes the parameter i as input from the Input.dat file, and generates a two-column numerical .dat file as output. Next, the Output.dat file has to be imported and manipulated. Since the external program takes some time to run and the Do loop runs much faster, the external program is terminating abnormaly. I would like to know how to tell Mathematica to wait until the external program finishes its evaluation before to execute the Import command. Thank you. Luiz Melo. Do [ Export["Input.dat", i]; Run["SomeMath.exe"]; t = Import["Output.dat"]; tpos[i] = Select[t, #[[1]] > 0 &]; tneg[i] = Select[t, #[[1]] < 0 &], {i, 100}];