pipe

pipe

ri

 --------------------------------------------------------------- IO::pipe
      IO.pipe -> array
 ------------------------------------------------------------------------
      Creates a pair of pipe endpoints (connected to each other) and
      returns them as a two-element array of  IO  objects:  [ 
      _read_file_, _write_file_  ] . Not available on all platforms.
 
      In the example below, the two processes close the ends of the pipe
      that they are not using. This is not just a cosmetic nicety. The
      read end of a pipe will not generate an end of file condition if
      there are any writers with the pipe still open. In the case of the
      parent process, the  rd.read  will never return if it does not
      first issue a  wr.close .
 
         rd, wr = IO.pipe
      
         if fork
           wr.close
           puts "Parent got: <#{rd.read}>"
           rd.close
           Process.wait
         else
           rd.close
           puts "Sending message to parent"
           wr.write "Hi Dad"
           wr.close
         end
 
      _produces:_
 
         Sending message to parent
         Parent got: <Hi Dad>
 

refe

 IO.pipe
 --- IO.pipe
 
     pipe(2) [manual page] を実行して、相互につながった2つの
     IO オブジェクトを要素とする配列を返します。IO オブジェ
     クトの作成に失敗した場合は例外 Errno::EXXX が発生します。
 
     戻り値配列は最初の要素が読み込み側で、次の要素が書き込み側です。
 
         p pipe = IO.pipe    # => [#<IO:0x401b90f8>, #<IO:0x401b7718>]
         pipe[1].puts "foo"
         p pipe[0].gets      # => "foo\n"