Skip to content

Instantly share code, notes, and snippets.

@clicube
Last active December 11, 2015 17:29
Show Gist options
  • Save clicube/4635177 to your computer and use it in GitHub Desktop.
Save clicube/4635177 to your computer and use it in GitHub Desktop.
IO.named_pipe(path, create=true) path: path of named pipe (fifo) create: create pipe if true
class IO
def self.named_pipe(path, create=true)
if !File.exist?(path)&& create
system "mkfifo #{path}"
end
raise IOError.new("it is not named pipe") if File.ftype(path) != "fifo"
pout = File.open(path, "r+")
pin = File.open(path, "w+")
return pout, pin
end
end
if __FILE__ == $0
pout, pin = IO.named_pipe("nyan")
3.times do
pin.puts :nyan
end
pin.flush
3.times do
puts pout.gets
end
File.delete "nyan"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment