本文簡要介紹ruby語言中 PTY.open
的用法。
用法
open → [master_io, slave_file]
open {|(master_io, slave_file)| ... } → block value
分配一個 pty (pseudo-terminal)。
在塊形式中,產生一個包含兩個元素的數組 (master_io, slave_file
),塊的值從 open
返回。
PTY.open {|master, slave|
p master #=> #<IO:masterpty:/dev/pts/1>
p slave #=> #<File:/dev/pts/1>
p slave.path #=> "/dev/pts/1"
}
在非塊形式中,返回一個二元素數組 [master_io, slave_file]
。
master, slave = PTY.open
# do something with master for IO, or the slave file
兩種形式的參數是:
IO#raw!
可用於禁用換行符轉換:
require 'io/console'
PTY.open {|m, s|
s.raw!
# ...
}
相關用法
- Ruby PTY模塊用法及代碼示例
- Ruby PrettyPrint.current_group用法及代碼示例
- Ruby Pathname.<=>用法及代碼示例
- Ruby Pathname.children用法及代碼示例
- Ruby Process.groups用法及代碼示例
- Ruby Process.wait2用法及代碼示例
- Ruby Process.getpgrp用法及代碼示例
- Ruby Proc.eql?用法及代碼示例
- Ruby PrettyPrint.genspace用法及代碼示例
- Ruby PKey.sign_raw用法及代碼示例
- Ruby Profiler模塊用法及代碼示例
- Ruby Process.setproctitle用法及代碼示例
- Ruby PPMethods.comma_breakable用法及代碼示例
- Ruby Process.setrlimit用法及代碼示例
- Ruby Proc.prc ==用法及代碼示例
- Ruby Profiler.raw_data用法及代碼示例
- Ruby Process.uid用法及代碼示例
- Ruby Pathname.descend用法及代碼示例
- Ruby Process.pid用法及代碼示例
- Ruby Proc.ruby2_keywords用法及代碼示例
- Ruby Pathname.getwd用法及代碼示例
- Ruby PKey.generate_parameters用法及代碼示例
- Ruby Proc.new用法及代碼示例
- Ruby Process.detach用法及代碼示例
- Ruby Pathname.ascend用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 PTY.open。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。