I use a C program to generate a ".txt" file, and import this ".txt" file into Mathematica to do some calculations and export these calculations.

Due to limitation of data size in C program, I have to repeatedly

1.run a "*.out" program on terminal (which generates some random data I needed);

2.run the Mathematica program manually on Mathematica;

Is there any way that I can automate this process so I don't need to repeat this cycles manually? I probably need to repeat this cycles hundreds of times. Thanks in advance!

  • 1
    $\begingroup$ This reference.wolfram.com/language/tutorial/ExternalPrograms.html describes how to run external commands, like a.out, from within Mathematica and how to read in external files. Perhaps you could have a Do or While or For loop in Mathematica to control the repetition you desire $\endgroup$ – Bill Jul 22 '19 at 4:45
  • $\begingroup$ @Bill After reading this, I am still not sure how to run a.out within Mathematica exactly. $\endgroup$ – lol Jul 22 '19 at 11:33

Use RunProcess to run arbitrary executables.

  • $\begingroup$ Hi, I tried to create a Mathematica program under the same directory of the *.out file, and tried RunProcess["./a.out", "StandardOutput"], but it failed. Do you know what is the right way to do this? $\endgroup$ – lol Jul 22 '19 at 10:42
  • $\begingroup$ Use SetDirectory[NotebookDirectory[]] before using RunProcess. $\endgroup$ – Roman Jul 22 '19 at 11:42
  • $\begingroup$ @Roman It works! Thanks! $\endgroup$ – lol Jul 22 '19 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.