Announcement

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

  • Test if operating in batch mode within a do-file

    Is there a way to test whether Stata is operating in batch mode (that is, using the -b command line option running from a Unix prompt) inside a do-file? As opposed to interactive mode within the GUI.

    In particular, I want to only run graph commands if the do-file is being run interactively, though more generally I could see being able to query for batch mode would be useful.

    I have already looked at the variables reported with the "set" command and that does not seem to contain info about batch mode versus interactive mode.

  • #2
    You can check the value for c(mode), EG:

    Code:
    if c(mode) == "batch" {
    do something
    }
    You may also want to take a look at the other system values Stata keeps track of with

    Code:
    creturn list
    -Pete

    Comment


    • #3
      The Stata manual pages for Unix section of the Getting Started With Stata for Unix PDF (included with your Stata installation (since version 11) and accessible from within Stata - for example, through Stata's Help menu) includes the following in its description of the stata command:

      ... whenever Stata is running without a terminal, it sets c(mode) to contain batch. If Stata is running in interactive mode, c(mode) is set to be empty. See [P] creturn.
      (Crossed in cyberspace with Pete's response.)
      (Let me add that c(mode) is not limited to Stata for Unix.)
      Last edited by William Lisowski; 12 Sep 2016, 12:52.

      Comment

      Working...
      X