require'pty'beginPTY.spawn("ruby output.rb")do|stdin,stdout,pid|ppidbeginstdin.eachdo|line|pline.stripendrescueErrno::EIOendendrescuePTY::ChildExitedputs"The child process exited!"end
require "mkfifo"
if File.pipe?("named_pipe") || File.mkfifo("named_pipe")
File.open("named_pipe", "w+") do |file|
10.times do |t|
file.puts "2"
file.flush
sleep 1
end
end
end
读进程
$ cat reader.rb
file = File.open("named_pipe", 'r+')
while !file.eof?
line = file.readline
puts line
end