これを修正するさまざまな方法をチェックアウトしましたが、環境に固有のものである可能性があります。Rubyでスクリプトを作成して、リモートサーバーにtelnetでログインし、シェルタイプを入力して(ログイン後のプロンプトで、前に「プロンプト」がありません)、次のプロンプトでユーザーIDを入力します。現在、ユーザーとパスを介してログインしていますが、用語の部分でフリーズしています。私は正規表現、文字列、スリープを使用してから puts("xterm" を使用しようとしましたが、このプロンプトを通過することはできません。ハングアップしているコードのスニペットとそれに沿った出力を次に示します。
$telnet = Net::Telnet::new("Host" => 'hostname',
"Output_log" => 'output.txt',
"Dump_log" => 'Dump.txt',
"Binmode" => false,
"Timeout" => false,
"Prompt" => /.* $ $/) { |c| print c }
$telnet.login("user", "pass") { |c| print c }
$telnet.waitfor("TERM = (xterm) ")
$telnet.puts("xterm") { |c| print c }
$telnet.waitfor(Match => /Enter\s*$/) { |c| print c }
$telnet.puts("userid")
出力は次のとおりです。
HP-UX ds107492 B.11.11 U 9000/800 (tm)
login: user
Password:
Please wait...checking for disk quotas
. i
.[ci
.*s1^i
See /etc/copyright for copyright notices
You have mail.
'You have mail.'
TERM = (xterm)