This is the mail archive of the cygwin@cygwin.com 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]

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 
1.5.5-1.

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:
http://f2.pg.briefcase.yahoo.com/bc/bluelightning32@sbcglobal.net/vwp2?.tok=bc
aHCqSB8PSN9kVF&.dir=/public&.dnm=ForceCharIO.zip&.src=bc

To use it do something like:
ForceCharIO.exe ./pktdump_ex.exe

Please tell me if anyone has found a better solution.

 -Lightning strikes
AIM screen name: bleue foudre



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


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