paul@cosc.canterbury.ac.nz (06/13/90)
The following program illustrates a bug in the system(3f) function In Sun FORTRAN 1.0 (I think) on a Sun 4/330 running 4.0.3. character*80 fred read(*,fmt='(a)' ) fred write(*,fmt='(a)') fred status = system('date') read(*,fmt='(a)' ) fred write(*,fmt='(a)') fred end When executed with stdin connected to the terminal the program behaves as expected - the first line is read and written, the date(1) output is printed, then the second line is read and written. When input is redirected to come from a file, however, the program dies at the second read because end of file is true. The file that input is coming from does have two lines though!!!! Because the input file is file buffered (read in 8192 byte chunks), the whole file is read by read(2) in respone to the first read of the program. The first line is returned, and the second is buffered somewhere. When the second read is done the buffered second line should be returned. Instead a read(2) on the file is attempted, which of course returns EOF. It seems that system(3f) is flushing the input buffer when it shouldn't be. When input comes from the terminal there is no problem as the input is line buffered. I tried an equivalent C program which worked as expected. Is this a known bug? Is there a patch? A workaround (could use fork and exec - can the equivalent of a setbuf be done from Fortran?). A fixed later version?