Skip to content

Instantly share code, notes, and snippets.

@film42
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save film42/7c828adba205aba08fde to your computer and use it in GitHub Desktop.
Save film42/7c828adba205aba08fde to your computer and use it in GitHub Desktop.
class BashQueue
FIFO_QUEUE = '/tmp/channel'
# Setup fifo queue called channel
def self.ensure_setup!
unless ::File.exist?(FIFO_QUEUE)
`mkfifo #{FIFO_QUEUE}`
end
end
def self.recv
ensure_setup!
::File.read(FIFO_QUEUE)
end
def self.send(data)
ensure_setup!
::File.write(FIFO_QUEUE, data)
end
end
BashQueue.send("Hello?")
# In terminal run: "read line < /tmp/channel; echo $line"
puts BashQueue.recv
# In terminal run: "echo 'Hi! :)' > /tmp/channel"
# OUTPUT:
# -------
# Sending Data
# Recv data
# Hi :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment