output redirection from a compat

Guy Harris guy at rlgvax.UUCP
Sat Jun 9 10:57:02 AEST 1984


> THe chess program supplied with Berkeley (4.1 and 4.2) runs as a pdp-11
> compatibility package. Note the following behavior:

...

> 2. Then redirect the output thru a simple filter like cat.

> chess |& cat -u

> and do the same things. This time no error message, no format
> characters and Oh,yes, the title "Chess" is held till the end. When you
> resign, all the stacked output tumbles out.

> I have tried many ways to overcome this with no success, including
> trying piping from a C program. I have run the v7trc (trace compat) to
> see what is happening and it looks like somehow the program is
> determining that the output is redirected and holding on to some
> messages. It runs properly under an emacs shell so I guess mpxio might
> help.

Followup:

> You have to change the chess program itself to do ``fflush''es
> after writing a line to stdout, or change the compat C library to
> fflush even if (!isatty(1)).

The problem with "chess" would probably have existed on a PDP-11 as well
(sorry, we don't have any here any more so I can't test that).  Chris
Torek's followup is correct; since the output of "chess" is not a terminal, it
doesn't do character-at-a-time writes, but buffered 512-bytes-at-a-time
writes.  That's the standard behavior for the Standard I/O Library, which
I presume the V7 PDP-11 "chess" used.

Unfortunately, it's a bit hard to change the chess program, as the source
doesn't come with any version of UNIX later than V7 and it's in a mixture
of C and PDP-11 assembler.  You'd have to get the source from a V7 tape
and get the PDP-11 C compiler, assembler, and linker running in compatibility
mode (the PDP-11 assembler is written in assembler, so it will only run
in compatibility mode on a VAX).

This'll probably happen on a VAX as well; it will flush "stdout" whenever
a Standard I/O read is done on "stdin", but only if "stdout" is line-buffered;
if it's not going to a terminal, it won't be line-buffered but block-buffered.
(This may be different in 4.2BSD; I checked our 4.1c source.)

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.unix.wizards mailing list