I am trying to create a named pipe inside Ruby. Besides using the system
command (system("mkfifo #{pipe_name}")
), is there a native Ruby function allowing me to do this?
Asked
Active
Viewed 4,211 times
7

Darshan Rivka Whittle
- 32,989
- 7
- 91
- 109

Yang Guan
- 81
- 1
- 5
-
Is there any benefit to a Ruby function over using the system command? – Velizar Hristov Jul 03 '15 at 18:51
1 Answers
10
Current versions of Ruby (starting with 2.3.0) now have a native File::mkfifo:
File.mkfifo('pipe_name')
Old answer for older versions of Ruby:
I don't believe there's anything fully native, but there's the mkfifo gem.
Install like this:
gem install mkfifo
Then use like this:
require "mkfifo"
File.mkfifo('pipe_name')

Darshan Rivka Whittle
- 32,989
- 7
- 91
- 109
-
There also seems to exist an all-in-one solution https://github.com/shurizzle/ruby-fifo – Casper Jun 22 '13 at 05:23
-
1If you look closely, these two gems are from the same author. "mkfifo" was created 11 months ago while "ruby-fifo" was created 3 years ago but I am not sure which one is better. mkfifo bundles fifo into the File class so one might use a fifo just as a regular file. – Yang Guan Jun 22 '13 at 05:59
-
-
1A native [File::mkfifo](https://ruby-doc.org/core-2.5.0/File.html#method-c-mkfifo) was introduced in Ruby 2.3.0. – Steve Mar 28 '18 at 08:06
-
@Steve Thanks for letting me know—I've updated my answer. – Darshan Rivka Whittle Mar 28 '18 at 11:29
-
The native method isn't implemented on Windows. github.com/shurizzle/ruby-fifo says it's cross-platform. – Benjineer Mar 08 '19 at 03:09