Run graphical hello world from command line

I have modified the example given at https://racket-lang.org/:

#lang racket/gui

(message-box "Hello, world" "hello world")

It works fine in dr racket. How do I run it from the command line?

I saved it in a file hello.rkt, and ran:

racket -f hello.rkt

and also

gracket -f hello.rkt

to no avail. I don't get any feedback at the command line, but I don't get any output graphically, either.

racket --version
Welcome to Racket v8.3 [cs].

cat /etc/linuxmint/info
RELEASE=20.2
CODENAME=uma
EDITION="Cinnamon"
DESCRIPTION="Linux Mint 20.2 Uma"
DESKTOP=Gnome
TOOLKIT=GTK
NEW_FEATURES_URL=https://www.linuxmint.com/rel_uma_cinnamon_whatsnew.php
RELEASE_NOTES_URL=https://www.linuxmint.com/rel_uma_cinnamon.php
USER_GUIDE_URL=https://www.linuxmint.com/documentation.php
GRUB_TITLE=Linux Mint 20.2 Cinnamon

Thanks for any helpful advice!

1 Like

The -f option is for loading non-module files, which is an old and mostly obsolete manner of using Racket. So what your commands did is load your file's module declaration... but then nothing told Racket to actually require (instantiate) the module, so Racket just exited.

You can use the -t option instead:

racket -t hello.rkt
gracket -t hello.rkt

Or you can just omit it; this also works:

racket hello.rkt
gracket hello.rkt

The two are slightly different in how they process command-line options after the module file name: in the -t version Racket tries to process any subsequent options in the command line (up to a --), but in the second version, Racket just forwards all of subsequent options to your program.

4 Likes

Sheesh. I feel dense. That worked perfectly and explained what was happening.