by Jon Ripley, May 2006

In some cases it is important to know what environment your program is running in so you can make different choices to suit the environment.

There are three methods to run a BBC BASIC program:
  • From the BBC BASIC Editor (IDE)
  • An uncompiled program run using the interpreter
  • Running a compiled program

To determine the environment a program is running in use code similar to the following:
      SYS "GetCommandLine" TO cmd%
      CASE TRUE OF
        WHEN INSTR($$cmd%, "bbcwin.exe") > 0:PRINT "Run from editor"
        WHEN INSTR($$cmd%, "bbcwrun.exe") > 0:PRINT "Run by interpreter"
        OTHERWISE:PRINT "Program is compiled"
      ENDCASE
Here we read a pointer to the command line arguments used to start the program and PRINT a different response for each possible case. It is not possible to use the special variable @cmd$ as this contains insufficient information.

Refactoring this code into a function is simple:
      DEF FN_GetRunEnvironment
      LOCAL cmd%, ret%
      SYS "GetCommandLine" TO cmd%
      CASE TRUE OF
        WHEN INSTR($$cmd%, "bbcwin.exe") > 0:ret%=1
        WHEN INSTR($$cmd%, "bbcwrun.exe") > 0:ret%=2
        OTHERWISE:ret%=3
      ENDCASE
      =ret%
Here we create a function named FN_GetRunEnvironment which returns one of three possible values:

  • 1 - Program was run from the editor
  • 2 - Program was run using the interpreter
  • 3 - Program is compiled



by Richard Russell, November 2010

If you want to know whether a program is compiled or not, you can use this simple test:
      IF INSTR(@lib$,@tmp$) THEN PRINT "Program is compiled"