1

I am trying to get two fortran programs to communicate through a named pipe but the reading program is hanging. My command look like this:

> mkfifo /tmp/myfifo
> ./app/fortw /tmp/myfifo &
> ./app/fortr /tmp/myfifo

where fortw prints the numbers 1 to 10 and 'fortr' reads them like this

open ( unit = nsave, file = outputfile , form = 'formatted', access = 'stream' )
do while ( .TRUE. )
read ( unit = nsave, fmt = *, end = 10), j
write( 6, *), j
end do

10 continue

It prints the numbers 1 - 6 and then hangs so i have to do fg then C^C to stop it.

If I replace ./app/fortr with cat, or an equivalent c++ program, then I get the numbers 1 to 10 as expected so the problem seems to be with the reading not the writing. But if I read from a normal file rather than a fifo, ./app/fortr gives the expected result.

Should I expect to be able to get this to work, and it so, how?

UPDATE:

A more minimal example. If test contains the numbers 1 to 10, then

./app/fortr test

prints the numbers 1 to 10

but

 ./app/fortr <( cat test )

prints the numbers 1 to 6 and hangs

paco_uk
  • 445
  • 1
  • 5
  • 15
  • Sounds like you need a flush. Try flush(6) after the write statement. It is not standard fortran. Alternatively, if after 10, you are ending the program, add close(6) before you terminate – cup May 25 '14 at 12:09
  • 1
    `Flush` is standard Fortran. https://software.intel.com/sites/products/documentation/doclib/stdxe/2013/composerxe/compiler/fortran-mac/GUID-188AE6E5-7E3A-41EA-AE71-F0726FC5024C.htm – Vladimir F Героям слава May 25 '14 at 12:22
  • Unfortunately, add flush(6) and close(6) to the reading program doesn't change the result. It still hangs after reading 6 numbers – paco_uk May 25 '14 at 12:26
  • Which compiler do you use? What code gives you iostat of read operations? – Peter Petrik May 26 '14 at 10:22
  • I am using gfortran. It seems to work for now if I add, `action = "read"` to the open command. I'm new to fortran though so I don't know why that helps or if it is likely to continue working. – paco_uk May 26 '14 at 17:45
  • @Peter I am now using `iostat = stat` in my read operations as well so I can check it. – paco_uk May 26 '14 at 17:47
  • @paco_uk , so what it gives you? – Peter Petrik Jun 04 '14 at 06:47
  • Possible duplicate of [Read on closed named pipe blocks](http://stackoverflow.com/questions/33670749/read-on-closed-named-pipe-blocks) – francescalus Nov 12 '15 at 13:51

0 Answers0