Write to fifo (named pipe)

I am trying to get a fortran 90 application to open fifo and write formatted data to it. I divided this into a minimal example. Let foo.f90 be the following program:

 program foo open(1,file='fifo',position='asis',action='write') write(1,*)'Hello, world!' write(1,*)'Goodbye.' end program 

Now compile and run the program:

 $ gfortran-4.7.1 -o foo foo.f90 $ rm -f fifo $ ./foo $ cat fifo Hello, world! $ rm -f fifo $ mkfifo fifo $ cat fifo > bar & [1] 6115 $ strace -o foo.st ./foo At line 3 of file foo.f90 (unit = 1, file = 'fifo') Fortran runtime error: Invalid argument [1]+ Done cat fifo > bar $ tail foo.st write(3, " Hello, world!\n", 15) = 15 lseek(3, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek) ftruncate(3, 18446744073709551615) = -1 EINVAL (Invalid argument) write(2, "At line 3 of file foo.f90 (unit "..., 52) = 52 write(2, "Fortran runtime error: ", 23) = 23 write(2, "Invalid argument", 16) = 16 write(2, "\n", 1) = 1 close(3) = 0 exit_group(2) = ? +++ exited with 2 +++ 

Thus, the program works quite well when written to a regular file. However, when writing to fifo, it tries to resize the file after the first recording, terminating the application after that.

I'm new to Fortran, so I'm not sure if this is a bug in gfortran, or is there a way to open a file that will suppress this syscall ftruncate . I would prefer to follow a formatted sequential approach: my lines have different lengths, and I would prefer not to specify the record number with each write .

+8
linux fortran named-pipes gfortran fortran90
source share
1 answer

This is an old function (don’t even dare to think of it as an error!) In libgfortran , which was patched backwards but was re-introduced for the GCC 4.7 branch, more specifically in SVN version 180701 . Apparently, gfortran developers are not testing their I / O code with named pipes.

You must use an older version of gfortran (works with 4.6.1) or another Fortran compiler from another provider. I will send a bug report to GCC.

+4
source share

All Articles