Question

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.

Was it helpful?

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.

OTHER TIPS

Instead of changing the program, on Linux you can also experiment with changing the buffer mode from the command line using stdbuf (although obviously any setvbuf calls in the application will override this). For example, you could try:

stdbuf -oL ./adventure | cat

A similar effect can also be achieved with unbuffer (comes with expect) and script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top