Reading from blocking fifo pipe in shell script

Hi!!

I have a problem reading from a fifo pipe in shell script.

The idea is simple, I have a C program with two pipe files:

  • An input pipe I use to send commands in shell script to the C program (echo "command" > input.pipe)
  • An output pipe that I read the result of the command also in shell script (cat output.pipe)

The problem is in the cat output.pipe
After output the data the cat process remains blocked (like a "tail -f") waiting for data.

It's possible to avoid this state?? (It's possible the cat terminates when the pipe not contains more data? Something like non-blocking read)

Thank you very much

cat is waiting for input from the keyboard, enter CTRL+D to close it.

Regards

Thx Franklin, your solution works in console mode, but I'm looking for a clean scripting solution.

Any ideas?

Consider what "echo "command" > input.pipe" does. It opens the pipe, writes some data, and then closes the pipe. Your C program needs to do likewise. For each command, it must open the output pipe, write some data, and then close the pipe. This close will cause your cat process to encounter eof of its side of the pipe and then it will exit.

Thank you to all,

The solution I found is to write a little C wrapper software that makes non-blocking read to the pipe (with the flag O_NONBLOCK)

When all the avaliable data is read, the program terminates itself

Thanks!