私のプロジェクトのために、Net::SSH::Telnet ライブラリにいくつかの機能を書き込もうとしています。具体的には、私が書いたコマンドの終了ステータスを読み取ることができる必要があります。
これは、私が変更している Net::SSH::Telnet ライブラリの元のソースです。
@buf = ""
@eof = false
@channel = nil
@ssh.open_channel do |channel|
channel.request_pty { |ch,success|
if success == false
raise "Failed to open ssh pty"
end
}
channel.send_channel_request("shell") { |ch, success|
if success
@channel = ch
waitfor(@options['Prompt'], &blk)
return
else
raise "Failed to open ssh shell"
end
}
channel.on_data { |ch,data| @buf << data }
channel.on_extended_data { |ch,type,data| @buf << data if type == 1 }
channel.on_close { @eof = true }
end
@ssh.loop
そして今、私が行った変更は次のとおりです。
@stderr = ""
@exit_code = nil
@buf = ""
@eof = false
@channel = nil
@ssh.open_channel do |channel|
channel.request_pty { |ch,success|
if success == false
raise "Failed to open ssh pty"
end
}
channel.send_channel_request("shell") { |ch, success|
if success
@channel = ch
waitfor(@options['Prompt'], &blk)
return
else
raise "Failed to open ssh shell"
end
}
channel.on_data { |ch,data|
@stdout << data
@buf << data
}
channel.on_extended_data { |ch,type,data|
@stderr << data
@buf << data if type == 1
}
channel.on_request("exit-status") do |ch,data|
@exit_code = data.read_long
end
channel.on_close {
@eof = true
}
end
@ssh.loop
問題は、これを実行すると、@exit_code 変数が nil から変更されないことです。
私がこれを行っている理由は、次の 3 つの主要な機能が必要だからです。 3. プロンプトに応答する機能
私は Net::SSH::Telnet を選択して調整しました。なぜなら、それはすでに 1 と 3 を提供していたからです。2 番をサポートする
ように修正できると考えました。Net::SSH::Telnet の残りのソースは次のとおりです。
https://github.com/jasonkarns/net-ssh-telnet/
ここにはレポの分岐バージョンがあり、プルリクエストを喜んで受け入れます。
https://github.com/0x783czar/net-ssh-remotescript
また、これらの 3 つの機能を提供する他の Ruby ライブラリの提案があれば、どんな提案でも大歓迎です。