|
From: MARSHALL K. <Kei...@to...> - 2003-09-10 12:34:10
|
Hi Guys,
I am having trouble with a program which reads from stdin,
and then does some processing of the data, stopping when
it reaches the end of the input stream. When I compile the
program using MinGW, then run it in RXVT, I can't make it
break out of the processing loop.
The following trivial program illustrates the problem:
#include <stdio.h>
int main()
{
char buf[2];
setvbuf( stdin, NULL, _IONBF, 0 );
while( ! feof( stdin ) )
fread( buf, 1, 1, stdin );
printf( "done\n" );
return( 0 );
}
Using MinGW 3.0.0-1, in the MSYS 1.0.9 RXVT console,
if I call the above, say "mytest.c", and compile it with ...
make mytest
then run it interactively, it simply hangs in the while loop; it
will echo any keys I type, but neither ^D nor ^Z seem to close
the stdin stream, to allow it to drop out of the loop.
If I run the MinGW compiled executable in CMD.EXE, instead of
RXVT, then ^Z breaks out of the loop, as expected.
If I run it in RXVT, but pipe its input from cat ...
cat | mytest
then ^D makes cat close the pipe, and the loop in mytest breaks,
as expected.
If I run the MinGW executable in a Cygwin shell, then I observe
the same behaviour as in RXVT, but if I compile a Cygwin executable
from the same source, then ^D breaks the loop as expected, when
running mytest stand alone, in the Cygwin shell.
So ...
Is this a bug in RXVT, or am I missing something? I have tried
searching the archives, but could find nothing relevant.
MSYS' cat seems to handle ^D correctly; what does it do, that
my code does not?
Regards,
Keith.
|