Search code examples
pathstatabatch-processing

Automatically detect if using GUI or batch mode


I am using Stata both in the GUI and running scripts in batch mode using a slurm cluster. The filepaths need to be established differently in each use case but I would like to have one .do file where all of the paths are defined.

Is there a way to write a falsifiable if statement that can evaluate to true if run from the GUI and false if run in batch?

Something akin to

glob using_gui = T
if $using_gui == T {
    glob dir "/mydir"
} else {
    glob dir "D:/mydir"
}

But where $using_gui is automatically determined as T or F


Solution

  • As answered within the statalist question linked above, this can be answered with c(mode) so

    if "`c(mode)'" == "batch" {
        glob dir "/mydir" 
    } 
    else {
        glob dir "D:/mydir" 
    }
    

    There are many ways to skin a cat. See help creturn for like options.