require 'net/telnet' # リモートホスト "foobar" に接続 # タイムアウトは 10 秒 localhost = Net::Telnet.new("Host" => "localhost", "Timeout" => 10) # ログインし、プロンプトが出るまで待ち合わせる telnet.login("your name", "your password") {|c| print c} # ls コマンドを実行し、実行後、プロンプトが出るまで待ち合わせる telnet.cmd("ls") {|c| print c} # sleep で 5 秒 telnet.cmd("sleep 5 && echo foobar &") {|c| print c} STDOUT.flush # <- これがないとここまで処理が来てることがわかりにくい # 前のコマンドの出力を待ち

