I want to store the stdout from a process into a buffer and have the buffer emptied once read, FIFO style.

I know that I can pipe the stdout, but the pipe/file will keep growing and contain data that I have already read. I just want the fresh data.

command > named_pipe &

Are there any other inbuilt methods, similar to a buffer in a network socket, that I can redirect data to?

  • What is "fresh data"? – Andy Dalton Feb 13 '18 at 15:10
  • @AndyDalton Data that I have not already read/processed. Using the socket analogy I can perform a read which empties the buffer. Data that I have not read is still in the buffer. – matt.baker Feb 13 '18 at 15:11
  • What you just described is also the semantics of a named pipe. – Andy Dalton Feb 13 '18 at 15:17

I don't understand how named pipes don't solve your problem. This example uses two shell interfaces, shell_1 and shell_2. I indent I/O from/to shell_2 more than that of shell_1 to try to differentiate what I/O is occurring from which shell.

$ mkfifo my_pipe
(shell_1) $ echo hi > my_pipe # Blocks waiting for a reader
    (shell_2) $ cat my_pipe # Unblocks shell_1
    (shell_2) $ cat my_pipe # blocks -- does not print "hi" again
(shell_1) $ echo bye > my_pipe # Unblocks shell_2
    bye # Printed by shell_2
  • You're completely right! Thanks for the example. I don't know what I was doing before, but it's now working as expected. – matt.baker Feb 19 '18 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.