method
open

v1_9_2_180 -
Show latest stable
-
0 notes -
Class: PTY
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180 (0)
- 1_9_3_125 (12)
- 1_9_3_392 (0)
- 2_1_10 (-38)
- 2_2_9 (0)
- 2_4_6 (6)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
open()
public
Allocates a pty (pseudo-terminal).
It returns an array which contains an IO object and a File object. The former is the master of the pty. The latter is the slave of the pty.
If a block is given, it yields the array instead of return. The value of the block is returned. master_io and slave_file is closed when return if they are not closed.
The path name of the terminal device can be gotten by slave_file.path.
PTY.open {|m, s| p m #=> #<IO:masterpty:/dev/pts/1> p s #=> #<File:/dev/pts/1> p s.path #=> "/dev/pts/1" } # Change the buffering type in factor command, # assuming that factor uses stdio for stdout buffering. # If IO.pipe is used instead of PTY.open, # this code deadlocks because factor's stdout is fully buffered. m, s = PTY.open system("stty raw", :in=>s) # disable newline conversion. r, w = IO.pipe pid = spawn("factor", :in=>r, :out=>s) r.close s.close w.puts "42" p m.gets #=> "42: 2 3 7\n" w.puts "144" p m.gets #=> "144: 2 2 2 2 3 3\n" w.close # The result of read operation when pty slave is closed is platform dependnet. ret = begin m.gets # FreeBSD returns nil. rescue Errno::EIO # GNU/Linux raises EIO. nil end p ret #=> nil