首页 > 解决方案 > tput:在使用 Ruby Net:SSH 时没有指定 $TERM 的值并且没有指定 -T

问题描述

我正在使用 Ruby Net:SSH lib 与远程 PC 建立 ssh 连接,然后执行远程 cmd。当我开始我的 SSH 连接时,我没有问题,但有时,不是在任何地方,当我使用 exec 时!我有一个错误返回到 stderr,它是“tput:$TERM 没有值并且没有指定 -T”。

代码示例:

Net::SSH.start(nodeAddress, nodeLogin, :password => nodePassword, :port => nodePort) do |ssh|
 ssh.exec! "cat \"#{sftpSshKey}\"" do |channel, stream, data|
  if(stream == :stderr)
   return "error tput"
  end
 end
end

如果有人有想法或已经有这个问题。

cat 的示例工作正常,如果我使用它,我会收到“tput”错误:

ssh.exec! "test -r \"#{sftpSourceFile}\" && echo \"Read\" || echo \"NRead\"" do |channel, stream, data|

如果我使用它,我没有错误:

ssh.exec! "test -w \"#{nodeDestinationPath}\" && echo \"Write\" || echo \"NWrite\"" do |channel, stream, data|

问候。

标签: rubysshnet-sshremote-executiontput

解决方案


这个来自 Net::SSH 源代码的示例展示了如何使用通道来执行交互式命令,然后读取命令的输出,并为命令提供输入。

      #   ssh.open_channel do |channel|
      #     channel.exec("/invoke/some/command") do |ch, success|
      #       abort "could not execute command" unless success
      #
      #       channel.on_data do |ch, data|
      #         puts "got stdout: #{data}"
      #         channel.send_data "something for stdin\n"
      #       end
      #
      #       channel.on_extended_data do |ch, type, data|
      #         puts "got stderr: #{data}"
      #       end
      #
      #       channel.on_close do |ch|
      #         puts "channel is closing!"
      #       end
      #     end
      #   end
      #
      #   ssh.loop

推荐阅读