Swipl should return an exit status code by default

A proposal regarding the use of exit status codes.

Currently, a simple pipe to swipl that is clearly wrong will still return 0 as status code:

echo "...THIS_IS_CLEARY_WRONG_AND_WILL_CRASH..." | swipl; echo $?

As far as I understand, because the swipl interactive environment is the default goal it will always return 0 as exit code, since it starts the interactive environment fine. But this makes CI testing and the like a bit tedious. For instance, when I want to install a pack, I want to know whether is has done so successfully.

echo "pack_install(hdt, interactive(false))." | swipl

Of course, I could make a new file and specify a goal, but I do think that is kind of tedious when running simple prolog rules like this in CI for instance.

My proposal:

Create a command line flag which handles the whole STDIN as the default goal.

1 Like

The normal way to do this is to use -g goal, as in

swipl -g "pack_install(hdt, interactive(false))" -t halt

The -t halt ensures exit 0 if all -g goals succeeded. If a goal fails or raises an exception it exits with an error status.

3 Likes