This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: isatty gives wrong result via ssh

Please, don't

On Nov 29 11:49, Konstantin Kouptsov wrote:
> On 11/26/2012 11:04 AM, Corinna Vinschen wrote:
> > On Nov 26 10:08, Konstantin Kouptsov wrote:
> >> On Windows, if I compile it using a Microsoft compiler:
> >>
> >> C: > cl /out:checktty.exe checktty.c
> >>
> >> the program behaves correctly when I run it from a DOS prompt or
> >> from a Cywin's bash prompt. However, if I connect to the Windows
> >> computer running Cygwin's sshd service from another Linux or
> >> Windows computer, it always gives the same result:
> >>
> >> $ ./checktty.exe
> >> not a tty
> >>
> >> $ ./checktty.exe < checktty.c
> >> not a tty
> >> [...]
> > Cygwin pseudo ttys are implemented as pipes, and the msvcrt runtime
> > has no idea about that.  It sees a pipe and that's no tty from its
> > POV.
> > 
> >> Given that I must compile the program using Microsoft's compiler on
> >> Windows, how this can be worked around?
> > 
> > The workaround is to implement your own isatty function which recognizes
> > Cygwin pseudo ttys as well.  I had a customer asking this question, too,
> > at one point and I sent them example code.  I attached it to this mail.
> Your example code was very helpful.
> A followup question. My Windows application works with the Windows
> Console API, and uses functions such as GetConsoleMode/SetConsoleMode,
> GetConsoleScreenBufferInfo, SetConsoleCursorPosition,
> ScrollConsoleScreenBuffer etc. When I connect via ssh from Linux to
> the Windows box running Cygwin sshd, and then laungh this application,
> none of these apparently work. Same if I connect from one
> Windows/Cygwin box to another Windows/Cygwin box and run it.

As I wrote before, your pseudo tty is a pipe, not a console.  One of the
unfortunate issues in Windows is the fact that consoles are not kernel
objects, and that they use their own set of functions, rather than
allowing to control them via escape sequences.  Since your process is
not connected to a console, the console functions have no effect.

> Presumably, here, I should be using a Unix-like console control
> interface, and link against ncurses port, provided with Cygwin.

You can't link Cygwin libs against native Windows applications.
They require the Cygwin DLL to run.

> [...]
> Also, I see there are test executable in lib/ncurses/test. Where can I
> see the source code for them?

In the ncurses source package, available via setup. 


Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]