ruby - 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|
问候。
解决方案
这个来自 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
推荐阅读
- reactjs - 使用下拉选择值作为 api 参数抛出名称变量未定义错误
- machine-learning - 无法使用 CNN 模型获得输出
- google-apps-script - 将 Google Analytics(分析)数据提取到 Google 表格中
- bash - Linux 检查 PATH 是否存在
- c# - 错误“只有赋值、调用、递增、递减、等待和新对象表达式可以用作语句”
- pdf - 在 rmarkdown YAML 中为 pdf 输出设置字体(字体)
- javascript - 用于服务器 api 调用的 useEffect 中的空数组与父级中的 useCallback
- android - 当文本进入新行时,从下到上增加 TextView 的高度
- html - 打破表格行 CSS
- python - 如何在文本文件的排序二维列表中打印 3 种不同类型的值?