Last active
August 29, 2015 14:25
-
-
Save film42/7c828adba205aba08fde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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