Next: , Previous: , Up: Forth Words   [Contents][Index]


5.29 Passing Commands to the Operating System

Gforth allows you to pass an arbitrary string to the host operating system shell (if such a thing exists) for execution.

sh ( "..." –  ) gforth-0.4 “sh”

Execute the rest of the command line as shell command(s). Afterwards, $? produces the exit status of the command.

system ( c-addr u –  ) gforth-0.4 “system”

Pass the string specified by c-addr u to the host operating system for execution in a sub-shell. Afterwards, $? produces the exit status of the command. The value of the environment variable GFORTHSYSTEMPREFIX (or its default value) is prepended to the string (mainly to support using command.com as shell in Windows instead of whatever shell Cygwin uses by default; see Environment variables).

$? ( – n  ) gforth-0.4 “dollar-question”

Value – the exit status returned by the most recently executed system command.

getenv ( c-addr1 u1 – c-addr2 u2 ) gforth-0.4 “getenv”

The string c-addr1 u1 specifies an environment variable. The string c-addr2 u2 is the host operating system’s expansion of that environment variable. If the environment variable does not exist, c-addr2 u2 specifies a string 0 characters in length.