2

I am running Mathematica from the command line using more or less the method discussed here:

Call a Mathematica program from the command line, with command-line args, stdin, stdout, and stderr

I am just wondering; how do I control the exit code that the command line sees? For example, I am running my Mathematica code many times via a loop in a Bash script, and I want to terminate the loop if an exit(FAIL) is seen, i.e. the return code being greater than 0. That is, I want to terminate the Mathematica code early if something bad happens, and pass this information on to the calling script so I can abort the loop. I assume it must be possible, but I don't see anything about return codes in the documentation for e.g. Exit[].

Community
  • 1
  • 1
Ben Farmer
  • 2,387
  • 1
  • 25
  • 44

1 Answers1

3

Wait, I am just dumb; the documentation for Exit[] does indeed say the following:

"On most computer systems, Exit[n] can be used to pass the integer exit code n to the operating system."

https://reference.wolfram.com/language/ref/Exit.html

Andy
  • 49,085
  • 60
  • 166
  • 233
Ben Farmer
  • 2,387
  • 1
  • 25
  • 44