Last active
December 11, 2015 17:29
-
-
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
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 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