Search code examples
gforth

exiting forth with EXIT_FAILURE equivalent


Apologies if this has already been asked, but for some reason I can't seem to find this anywhere. I want to write a word that write some information to stderr, then exits forth, but sets the exit code before doing so. I know I can use bye to exit forth, but I can't find any mention anywhere of an analagy for exit(EXIT_FAILURE) in c.

i.e.

: word
    s" error" stderr write-file exit_failure ;
~ $ gforth -e 'word'
error

~ $ echo $?
1

how am I supposed to do this?


Solution

  • You can use the word (bye) to return an exit code. That will go around the normal processing that is in the regular bye, but it will get your exit code out. So, if you want to return 27 for some reasons

    27 (bye)

    will get it done