Menu

Cause of "Error opening terminal" message?

2015-10-31
2016-06-02
  • DanAaronGoldman

    DanAaronGoldman - 2015-10-31

    I have a curses application. It previously compiled using mingw from
    batch files, this program is stable, has been working for years.
    Recently, it compiles as 32-bit under msys2 with shell scripts.

    When I try to start it from a mintty window, it says:

    $ ./txu1-tpl-eg1.exe
    Error opening terminal: xterm-256color.
    
    $ file txu1-tpl-eg1.exe
    txu1-tpl-eg1.exe: PE32 executable (console) Intel 80386, for MS Windows
    
    $ echo $TERM
    xterm-256color
    
    $ pacman -Qsq term
    less
    mingw-w64-i686-termcap
    mingw-w64-x86_64-termcap
    mintty
    perl
    tmux-git
    
    $ echo $MSYSTEM
    MINGW32
    
    $ echo $PATH /mingw32/bin:/usr/bin:/bin:/c/Program
    Files/Common Files/Microsoft Shared/Windows
    Live:/c/Program Files (x86)/Common Files/Microsoft Shared/Windows
    Live:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Program
    Files (x86)/Intel/OpenCL SDK/3.0/bin/x86:/c/Program
    Files (x86)/Intel/OpenCL SDK/3.0/bin/x64:/d/Program Files
    (x86)/Putty:/d/ehdp/vn/batdir:/c/Program Files (x86)/Windows
    Live/Shared:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/ehdp/vn/ro/vn-exes/vcu1/:/home/ehdp/vn/ssdir/backups:/home/ehdp/vn/ssdir/compile:/home/ehdp/vn/ssdir/maintain:/home/ehdp/vn/ssdir/transfer:.
    

    When mintty starts, it says xterm-256color under "Options / Terminal
    / Type". I have tried changing to the other options (xterm, etc.),
    applying, exiting mintty, restarting, running export TERM=whatever. Each
    time, I get the same type error message, such as:

    $ ./txu1-tpl-eg1.exe
    Error opening terminal: xterm.
    

    The exact same txu1-tpl-eg1.exe application starts up and runs fine from a
    windows 7 "Command Prompt" (DOS Window).

    I installed and ran mc (midnight commander), which seems to also
    use ncurses. It runs perfectly uner mintty here, if that is any help.

    • Should a curses exe I compiile be able to run under mintty?
    • If yes, any idea why the error message and crash?

    I looked around the internet, could not find clues. Any help appreciated.

    Thanks,
    Daniel

     

    Last edit: David Macek 2015-11-17
  • Ray Donnelly

    Ray Donnelly - 2015-11-01

    If you can make a minimal testcase we'd be able to investigate this for you.

     
  • DanAaronGoldman

    DanAaronGoldman - 2015-11-01

    In other words, if I can create a small test C program that crashes, along with how I compile and run it, you can try reproducing and investigating the error?

     
  • Ray Donnelly

    Ray Donnelly - 2015-11-01

    Yeah.

     
  • DanAaronGoldman

    DanAaronGoldman - 2015-11-01

    It was pretty easy to make a test case:

    http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/helloworld.html

    lemur:1:/home/ehdp/vn/util/test$ cat ncurses-1.c
    /* Figure out msys2 crash */
    
    #include <stdio.h>
    #include <curses.h>
    
    int main()
    {
     initscr();   /* Start curses mode     */
     printw("Hello World !!!"); /* Print Hello World    */
     refresh();   /* Print it on to the real screen */
     getch();   /* Wait for user input */
     endwin();   /* End curses mode    */
    
     return 0;
    }
    
    lemur:1:/home/ehdp/vn$ echo $PATH
    /mingw32/bin:/usr/bin:/bin:/c/Program Files/Common Files/Microsoft Shared/Windows Live:/c/Program Files (x86)/Common Files/Microsoft Shared/Windows Live:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Program Files (x86)/Intel/OpenCL SDK/3.0/bin/x86:/c/Program Files (x86)/Intel/OpenCL SDK/3.0/bin/x64:/d/Program Files (x86)/Putty:/c/Program Files (x86)/Windows Live/Shared:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/ehdp/vn/ro/vn-exes/vcu1/:/home/ehdp/vn/ssdir/backups:/home/ehdp/vn/ssdir/compile:/home/ehdp/vn/ssdir/maintain:/home/ehdp/vn/ssdir/transfer:.
    
    lemur:1:/home/ehdp/vn/util/test$ echo $MSYSTEM
    MINGW64
    lemur:1:/home/ehdp/vn/util/test$ gcc -g -I /usr/include/ncurses/ ncurses-1.c -lncurses
    lemur:1:/home/ehdp/vn/util/test$ ./a.exe
    Error opening terminal: xterm-256color.
    
    lemur:1:/home/ehdp/vn$ echo $MSYSTEM
    MINGW32
    lemur:1:/home/ehdp/vn/util/test$ gcc -g -I /usr/include/ncurses/ ncurses-1.c -lncurses
    lemur:1:/home/ehdp/vn/util/test$ ./a.exe
    Error opening terminal: xterm-256color.
    

    When I tried running under Windows command window, it first complained about not finding libwinpthread-1.dll - I copied a.exe to same (non-system) directory as the DLL, and a.exe ran fine. I went back to mingw64 and mingw32 windows, recompiled the test case, copied a.exe to the directory with the dll, and the error message / crash still happened. I don't understand what's going on with the libwinpthread-1.dll under windows, but I think the "error opening terminal" error is not related. However, in case helpful:

    $ file *.dll
    libwinpthread-1.dll: PE32 executable (DLL) (console) Intel 80386 (stripped to external PDB), for MS Windows
    

    Please at least let me know if you can reproduce the problem.

    Daniel

    PS - When I compose this, the first hash-include is ENORMOUS, and the sourceforge decides it want italics for the little comment. Is there a way to tell the editor "text only, no fixin' up"? Anyway, the test case is exactly from the web site link shown on first line, in case any question.

     

    Last edit: David Macek 2015-11-17
  • David Macek

    David Macek - 2015-11-17

    ad formatting: You should be able to use three backqoutes on a separate line to start a code block and the same to end it, but it seems to not work here correctly. When clicking on the icon for code in the formatting bar, it surrounds the text with four tildes on separate lines, which does work.

     
  • David Macek

    David Macek - 2015-11-17

    A potential problem is that you're combining ncurses headers for msys2 and ncurses library for mingw-w64. The actual problem is that you're building an ncurses application for native Windows, which means you should be running it in a regular console window, not mintty.

    I don't know enough about ncurses to propose a solution for running these things in mintty. Not even winpty seems to help.

     
  • DanAaronGoldman

    DanAaronGoldman - 2015-12-13

    To test this further:
    - I installed pdcurses (windows curses library) to under the msys2 root.
    - Then, I compiled the test case program using pdcurses.
    - The exe run fine under Windows command prompt window.
    - Again, crashes under mintty, but this time reports a different problem:

    $ echo $MSYSTEM
    MINGW32
    
    $ echo $TERM
    xterm-256color
    
    $ cat ncurses-1.c
    /* Figure out msys2 crash */
    
    #include <stdio.h>
    #include <curses.h>
    
    int main()
    {
     initscr();   /* Start curses mode     */
     printw("Hello World !!!"); /* Print Hello World    */
     refresh();   /* Print it on to the real screen */
     getch();   /* Wait for user input */
     endwin();   /* End curses mode    */
    
     return 0;
    }
    
    $ cat temp.sh
    gcc ncurses-1.c -I d:/msys64/var/local/pdc34dll/ \
      -L d:/msys64/var/local/pdc34dll/ -lpdcurses
    
    $ ./temp.sh
    $ ./a.exe
    Redirection is not supported.
    

    Different values for TERM did not change the error message.

    http://savannah.gnu.org/bugs/?32077
    seems to be saying that others have noticed this same problem, and there could be a way to run a windows application under mintty. However, it's a little hard to figure out.

    http://neolit123.blogspot.com/2011/01/re-packing-gnu-nano-225-for-use-on.html
    seems kind of a similar story.

    https://github.com/mcandre/nano-win/tree/master/bin
    is more information. Also, a little hard to interpret. As with above links, references cygwin.

    If anyone has any ideas, let me know. The links suggest there may be some way a Windows curses program compiled under msys2 can run under mintty. I wish I knew for sure, yes or no. BTW, the reason I am interested in running under msys2 is to run gdb. Of course, I could also do that under the Windows command prompt. Just seems msys2 is a better development / testing environment.

    The formatting looks OK with the preview. Cross my fingers and click "post".

    Thanks,
    Daniel

     
  • David Macek

    David Macek - 2015-12-17

    Here is a ticket on the mintty project site: https://github.com/mintty/mintty/issues/56
    It could contain some information about running native terminal programs inside mintty.

     
  • DanAaronGoldman

    DanAaronGoldman - 2015-12-21

    Thanks. Hard to understand the ticket on the mintty site.

    https://github.com/mintty/mintty/issues/240 - is a separate mintty ticket I found that specifically references pdcurses and basically says it does not work under mintty.

    However, mc (midnight commander) runs fine under msys2 mintty. It seems to use ncurses (does it?).

    /usr/bin$ ldd mc
            ntdll.dll => /c/Windows/SYSTEM32/ntdll.dll (0x77ae0000)
            kernel32.dll => /c/Windows/system32/kernel32.dll (0x779c0000)
            KERNELBASE.dll => /c/Windows/system32/KERNELBASE.dll (0x7fefd8b0000)
            msys-glib-2.0-0.dll => /usr/bin/msys-glib-2.0-0.dll (0x468d20000)
            msys-iconv-2.dll => /usr/bin/msys-iconv-2.dll (0x3ff4f0000)
            msys-2.0.dll => /usr/bin/msys-2.0.dll (0x180040000)
            msys-intl-8.dll => /usr/bin/msys-intl-8.dll (0x3ff4a0000)
            msys-pcre-1.dll => /usr/bin/msys-pcre-1.dll (0x3ff210000)
            msys-ncursesw6.dll => /usr/bin/msys-ncursesw6.dll (0x3ff300000)
            msys-ssh2-1.dll => /usr/bin/msys-ssh2-1.dll (0x48c350000)
            msys-crypto-1.0.0.dll => /usr/bin/msys-crypto-1.0.0.dll (0x3ffb10000)
            msys-z.dll => /usr/bin/msys-z.dll (0x3fed30000)
    

    I get a similar result running ldd on the vim running under msys2. So the idea that mintty "can't run something compiled under curses" doesn't seem to be true.

    In addition, I can run the msys2 mc and vim programs under the windows cmd.exe (Command Prompt) window fine, I detect no problem. That's what I want to do. It seems to work with vim and mc.

    If vim and mc are NOT using curses, then what are they using for screen control?

    So a curses program can (apparently) be compiled under msys2 and run under either mintty or cmd.exe window. I'm just compiling it wrong, that's all. Under MINGW32 window:

    $ gcc -I /usr/include/ncurses curses-1.c -lncursesw
    $ ./a.exe
    Error opening terminal: xterm-256color.
    $ ldd a.exe
            ntdll.dll => /c/Windows/SYSTEM32/ntdll.dll (0x77ae0000)
            ntdll.dll => /c/Windows/SysWOW64/ntdll.dll (0x77cc0000)
            wow64.dll => /c/Windows/SYSTEM32/wow64.dll (0x751b0000)
            wow64win.dll => /c/Windows/SYSTEM32/wow64win.dll (0x75150000)
            wow64cpu.dll => /c/Windows/SYSTEM32/wow64cpu.dll (0x75140000)
            ??? => ??? (0x779c0000)
            kernel32.dll => /c/Windows/syswow64/kernel32.dll (0x75da0000)
            ??? => ??? (0x779c0000)
            ??? => ??? (0x778c0000)
            kernel32.dll => /c/Windows/syswow64/kernel32.dll (0x75da0000)
            KERNELBASE.dll => /c/Windows/syswow64/KERNELBASE.dll (0x76160000)
            msvcrt.dll => /c/Windows/syswow64/msvcrt.dll (0x75cc0000)
            libwinpthread-1.dll => /mingw32/bin/libwinpthread-1.dll (0x64b40000)
            USER32.dll => /c/Windows/syswow64/USER32.dll (0x76910000)
            GDI32.dll => /c/Windows/syswow64/GDI32.dll (0x76560000)
            LPK.dll => /c/Windows/syswow64/LPK.dll (0x75d90000)
            USP10.dll => /c/Windows/syswow64/USP10.dll (0x76300000)
            ADVAPI32.dll => /c/Windows/syswow64/ADVAPI32.dll (0x75a80000)
            sechost.dll => /c/Windows/SysWOW64/sechost.dll (0x77690000)
            RPCRT4.dll => /c/Windows/syswow64/RPCRT4.dll (0x76050000)
            SspiCli.dll => /c/Windows/syswow64/SspiCli.dll (0x75620000)
            CRYPTBASE.dll => /c/Windows/syswow64/CRYPTBASE.dll (0x75610000)
            IMM32.DLL => /c/Windows/system32/IMM32.DLL (0x75a20000)
            MSCTF.dll => /c/Windows/syswow64/MSCTF.dll (0x76640000)
    

    Could someone point me to how to compile it "right"? For example, how are mc and vim compiled? It would be nice if there was a simple example of how to compile a curses program correctly under msys2, so it runs under either msys2 or cmd.exe window. I would be willing to help write the example, if I had any idea of the "right" way.

    Any input appreciated.

    Thanks,
    Daniel

     

    Last edit: DanAaronGoldman 2015-12-21
  • DanAaronGoldman

    DanAaronGoldman - 2016-01-26

    In a recent mailing list post, I saw winpty (was not aware of it before) mentioned. It seems to at least partially fix the curses problem.

    The curses program, plus simple test curses programs I had presented, previously produced error messages like the following and crashed:

    $ txu1-tpl-eg1.exe
    Redirection is not supported.
    $
    

    With "winpty txu1-tpl-eg1.exe" the program at least starts up, looks perfect visually. The program responds to keyboard commands (eg, q to quit). Pressing ENTER goes to a submenu, and that works.

    Unfortunately, the arrow keys, PgUp, PgDn, Home, End keys don't work. They work correctly when the program runs under a windows 7 command window. Does anybody have a clue why the arrow keys do not work for running a pdcurses program under mintty / winpty?

    Daniel

    PS - http://blog.toonormal.com/2012/11/17/gcc-msys-mintty-pdcurses-winpty-and-good-times-in-the-shell/ is a related post I found, in case helpful for anyone.

     
  • DanAaronGoldman

    DanAaronGoldman - 2016-02-04

    I wanted to thank Greg Jung for sending a very helpful response. It might benefit some others.

    Run "C:\msys64\usr\bin\bash.exe --login -i" from within the windows 7 command prompt ("dos shell") and get a bash prompt. Then run the curses (compiled with pdcurses) program with "./txu1-tpl-eg1.exe" - it runs perfectly! Arrow keys work, everything looks / functions perfectly.

    Next, make a copy of the command prompt desktop icon, change the target to the command line given above, it works perfectly.


    I'm still confused about the difference between 1) mintty, 2) winpty from within mintty, 3) bash.exe from within dos window, and 4) dos window itself. For example, I notice that mc runs poorly under the bash.exe environment. Arrow keys don't work, colors get messed up, it is slow. Oddly, mc (same exe) runs perfectly when run directly from dos shell.

    Obviously, I don't really understand what's going on. It would be nice if someone who understands more about this could post some advice, related to different options for compiling and running curses applications under msys2.

    Anyway, at least the bash.exe option is good progress.

    Daniel

     
  • Logicae

    Logicae - 2016-06-02

    Hey !
    I too have been blocked by this problem with Ncurses and Mintty.
    however with the windows console works well.

    So to settle this problem,
    as stated in the documentation: http://linux.die.net/man/3/ncurses
    Global variables such as $TERM and $TERMINFO help ensure the "terminal description".

    So it only remains to prepare Minnty with a small scipt kind of preparation:

    export TERM=xterm
    export TERMINFO=<path_to_ncurse_build>/share/terminfo
    ./my_program.exe
    

    Important Note the compatibility with $TERM = xterm is still on top, so I continued my research ...
    Voila, here.

     

    Last edit: Logicae 2016-06-02
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.