isatty gives wrong result via ssh

Konstantin Kouptsov
Mon Nov 26 15:08:00 GMT 2012


I have a program, which I reduced to the following short code, which is intended to be compiled both on Linux and Windows. It is run either locally, from a local terminal prompt, or remotely, through ssh. It should detect whether it runs in an interactive session (with a command line) or in a pipe, and behave differently.

--- checktty.c ---
#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
#include <unistd.h>

int main()
		printf("not a tty\n");

When I compile it on Linux, and run from the local terminal, it performs as expected:

$ gcc -o checktty checktty.c
$ ./checktty
$ ./checktty < checktty.c
not a tty

Same happens when I connect to the Linux computer via ssh either from another Linux computer or from Windows (via PuTTY or Cygwin ssh).

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

(When I compile with Cygwin's gcc, everything is fine)

What happens here?

Given that I must compile the program using Microsoft's compiler on Windows, how this can be worked around?


Problem reports:
Unsubscribe info:

More information about the Cygwin mailing list