Definitely set FGLGUI=0. If you also still run in TUI mode, you may also consider an additional proprietary environment variable that allows you too distinguish between TUI programs to a terminal and running with no UI e.g.
IF FGL_GETENV("MY_RUN_MODE") = "FOREGROUND" THEN
OPTIONS INPUT WRAP
OPTIONS FIELD ORDER FORM
END IF
IF FGL_GETENV("MY_RUN_MODE") = "BACKGROUND" THEN
-- write error to output file
ELSE
ERROR error_text
END IF
Two gotchas
1. Default value in Genero of FGLGUI if not set is 1 (see
http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_Mig0000_013.html) . So either make sure it is set or have code of the form IF nvl(FGL_GETENV("FGLGUI"),1) = 1 if you are testing FGLGUI = 1
2. Don't start background programs via launchURL or shellexec on a .gdc file. If you are trying to set FGLGUI=0 in an .xcf file you are going down the wrong path. You can call them from GUI program with something like RUN "export FGLGUI=0; fglrun background-program" WITHOUT WAITING
It will also be in your interests to ensure that there is no unexpected UI code executed. A license is consumed when you use UI code. Note the output of this at the command line with FGLGUI=0
MAIN
RUN "fglWrt -a info users"
OPTIONS INPUT WRAP
RUN "fglWrt -a info users"
END MAIN
Separating UI from Business Logic not only helps avoid executing UI code but will also help with web services. This can't be called in a web service or background job ...
FUNCTION validate_field(value)
IF bad-value THEN
CALL FGL_WINMESSAGE("Error","Value must be good","stop")
END IF
END FUNCTION
... whereas this can be called from a GUI program, Web Service, or background job
FUNCTION valid_field(value)
IF bad-value THEN
RETURN FALSE, "Value must be good"
END IF
RETURN TRUE, ""
END FUNCTION
Reuben