This is the mail archive of the
mailing list for the Cygwin project.
Noncygwin programs wait for buffer to fill before outputting to ssh
- From: kstemen <kstemen at cs dot kent dot edu>
- To: cygwin at cygwin dot com
- Date: Sun, 14 Dec 2003 03:49:02 -0500
- Subject: Noncygwin programs wait for buffer to fill before outputting to ssh
If I run a console application that wasn't built in cygwin when I'm ssh'd into
a computer, it won't display the program's output until the program ends or
its buffer fills up. The only other discussion of this problem that I could
find was in http://www.cygwin.com/ml/cygwin/2003-07/msg00716.html. It said
upgrading to cygwin version 1.5.0-1 would fix the problem, but I already have
I don't have as much experience with cygwin as I do with VC++, so I dug into
its libraries. The problem originate's in VC++'s printf and _isatty functions.
Printf will only flush the buffer after each call if _isatty returns true.
_isatty will only return true if GetFileType says the file is FILE_TYPE_CHAR.
This was probably to speed up redirected IO.
I tried to figure out how to create a file of that type, but I couldn't find
anything short of creating a device driver. Instead, I made a program that
would hook into the GetFileType function and always return FILE_TYPE_CHAR if
the handle is one of the standard IO handles from GetStdHandle. I used someone
else's code from http://www.codeproject.com/dll/apihijack.asp, and it only
seems to work if msvcrt is statically linked. The other part of the program is
that it more gracefully handles ctrl-c through ssh, so the program has a
chance to flush its buffers then, even if msvcrt is dynamically loaded.
It's a bit of a hack, but I couldn't find any other way to do it. You can get
the source code to my program and the exe from:
To use it do something like:
Please tell me if anyone has found a better solution.
AIM screen name: bleue foudre
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html