delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/11/26/10:09:01

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-0.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL
X-Spam-Check-By: sourceware.org
Message-ID: <50B385F9.80103@kouptsov.com>
Date: Mon, 26 Nov 2012 10:08:41 -0500
From: Konstantin Kouptsov <konstantin AT kouptsov DOT com>
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/17.0 Thunderbird/17.0
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: isatty gives wrong result via ssh
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Hi,

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>
#else
#include <unistd.h>
#endif

int main()
{
	if(isatty(0))
		printf("tty\n");
	else
		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
tty
$ ./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?

Thanks,
Konstantin.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019