[Win10/Msys2] : swipl hangs at startup

Hi everybody

I’ve installted mingw-w64-x86_64-swi-prolog package on msys2.

Although the welcome message is printed, swipl hangs before prompt is displayed. ^C, ^D are inactive.
Seems to be a problem of std I/O.

Does somebody have an idea ?

Thanks a lot

Hi Didier,

I have written the “recipe” for the MinGW/Msys2 version. There is some yet-to-be-resolved problem with the terminal, so swipl appears unresponsive (especially, there is no prompt). Though it’s actually working, at least on my computer, see below.

Matthias@DESKTOP-A2T8IFC MINGW64 ~
$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.9-38-g21d9cac38-DIRTY)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

member(X, [1, 2, 3]).
X = 1 ;
X = 2 ;
X = 3.

halt.

Matthias@DESKTOP-A2T8IFC MINGW64 ~
$

Please give it a try. If you want a prompt and better “readline” support, use “start”:

$ start swipl

Then a new window should open and you should also see a prompt and have readline support. I don’t know how to fix this properly.

I searched a bit in the internet. It’s a mintty issue under Windows, see here:

If you also have python installed, you’ll see that they suffer from a similar problem.

Matthias@DESKTOP-A2T8IFC MINGW64 ~
$ python
Python 3.9.13 (main, May 19 2022, 07:22:26)  [GCC 11.3.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 123
123
>>> 123
  File "<stdin>", line 1
    123
       ^
SyntaxError: invalid syntax

The syntax error is from me typing 1-2-3-left-right-enter.

Yes, that’s right. It is working adding start.

Thank you.

That’s funny it works without on your computer. What is the secret ?

Good evening

Do you mean the program really “hangs” on your machine? Is it not just suppressing the prompt?

winpty is one more thing you could try:

Matthias@DESKTOP-A2T8IFC MINGW64 ~/swipl-devel
$ pacman -S winpty
(omitted the output)

Matthias@DESKTOP-A2T8IFC MINGW64 ~/swipl-devel
$ alias swipl="winpty swipl"

Matthias@DESKTOP-A2T8IFC MINGW64 ~/swipl-devel
$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.4.2)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

1 ?- member(X, [1, 2, 3]).
X = 1 ;
X = 2 ;
X = 3.

2 ?- member(X, [1, 2, 3]). %%%% obtained this one by "cursor up"
X = 1 .

2 ?- halt.

It hangs : it is what I can see on screen. I guess it’s what you explain about mintty.
I’m going to try what you suggest. Thanks again.

that’s working now with winpty. Nice.

You may also get away with

 set_stream(user_input, tty(true)),
 set_stream(user_output, tty(true)),
 set_stream(user_error, tty(true)).

to make the system believe it is talking to a terminal. Normally it tries to detect the Windows console and assumes it is not talking to a terminal if that discovery fails.

That’s the “secret” Didier was referring to a few posts above :slight_smile:

Interesting. Thank you, Jan.
I’m supposed to include these lines in a prolog startup file ?
I can’t inderstand concretely what I’ supposed to do.

It’s another subject but I’m taking the opportunity here :

?- current_prolog_flag(arch, Arch).
Arch = ‘x64-win64’.

As it is run in mingw64. Might be replaced by x64-mingw ? It would be more accurate and avoid my software getting confused.

Thanks again.
Nice night to you

In general, not. The system is supposed to find out it is talking to a human. There is no safe way to do so in Windows though (AFAIK), so if the system diagnostic fail you can help it a bit. So, if you use swipl.exe only in this config you may use this as a work-around. Better is to either provide the feedback to msys to fix the console compatibility or figure out how we can detect the msys console.

No. The identifier is first of all used to find compatible DLLs to use as plugins. MinGW should not be special in this respect. This tells the CPU is x64 and the API is win64. That is enough (mostly).