Search code examples
cgccfortranpipeadventure

C program refuses to pipe?


I am trying to compile the 1991 C port of the original Crowther/Woods FORTRAN Colossal Cave Adventure. The code is a horrible mess, but after changing certain sections of it it compiles and runs properly.

The problem is that when I attempt to pipe its output to another program or to a file, nothing shows up. ./adventure works fine, but ./adventure | cat doesn't print anything. Grepping for a call to fstat turns up nothing.

Is there some other way that the program might be detecting the pipe and going into silent mode? Even adding printf("Hello World"); as the first line of the main function doesn't cause anything to appear through cat.

EDIT: I'm using Jim Gillogly's version, but the link I got the source from has gone rotten. I will find another download link for it.


Solution

  • As the existing comments have said, stdout is probably block-buffered because it isn't opened to a terminal any more. Try adding the call:

    setvbuf(stdout, NULL, _IOLBF, 0);
    

    somewhere around the start of the program. This will change stdout to line-buffered mode, which will flush the output as soon as the program writes a newline.