Next: , Previous: Threading Words, Up: Words


5.28 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       “sh”

Parse a string and use system to pass it to the host operating system for execution in a sub-shell.

system       c-addr u –         gforth       “system”

Pass the string specified by c-addr u to the host operating system for execution in a sub-shell. 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       “dollar-question”

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

getenv       c-addr1 u1 – c-addr2 u2        gforth       “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.