Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Stata batch-mode exit status on error

    I would like to manage the execution of related scripts and want a general method for knowing if a script had an error. The standard way to do this is to check the return code, but Stata in batch-mode always seems to return an exit status of 0 (indicating no error) even when the code it's running produces an error (at least for v13 on Windows & Linux).

    $ stata-mp -b error 1
    $ echo $?
    0

    This seems odd. Is there anyway to have Stata return a non-0 exit status? Are non-zero return codes reserved for when the Stata executable has an error rather than the script having an error? Possible work-arounds (to hopefully be avoided) could be (a) checking the log file afterward or (b) having the script capture errors and write out the return code to a file.

  • #2
    The only way is to check the log file afterward, which while not ideal, works pretty well. See this gist for the way I do it (I use this with make all the time).

    Comment


    • #3
      Thanks for that code!

      Comment

      Working...
      X