SWI Prolog script without running a tty

I’m using: SWI-Prolog version 8.3.5

I want the code to start without needing a tty attached. For instance, for a server. But the solution has to be cross-platform as well.

But what I’m getting is:

Every way of starting SWI Prolog without a TTY halts immediatly. Even with the --no-tty option passed to SWI Prolog.

My code looks like this:

test.pl:

:- writeln("Hello world").

Running this without a tty will just make the script halt immediately without writing hello world.

At least two solutions:

$ swipl -g 'writeln("Hello world")' -g halt
Hello world

Another method: use the initialization/1 or initialization/2 directive to specify a goal. If that goal ends with a call to halt/0, or halt/1, you won’t get the top-level prompt.

(BTW, the --no-tty doesn’t do what you think it does.)

1 Like