【发布时间】:2010-10-05 18:03:45
【问题描述】:
我有一个脚本,它应该在我的本地机器上模仿 ffmpeg,通过将命令发送到远程机器,在那里运行然后返回结果。 (见previous stackoverflow question.)
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
require 'net/sftp'
require 'highline/import'
file = ARGV[ ARGV.index( '-i' ) + 1] if ARGV.include?( '-i' )
puts 'No input file specified' unless file;
host = "10.0.0.10"
user = "user"
prod = "new-#{file}" # product filename (call it <file>-new)
rpath = "/home/#{user}/.rffmpeg" # remote computer operating directory
rfile = "#{rpath}/#{file}" # remote filename
rprod = "#{rpath}/#{prod}" # remote product
cmd = "ffmpeg -i #{rfile} #{rprod}"# remote command, constructed
pass = ask("Password: ") { |q| q.echo = false } # password from stdin
Net::SSH.start(host, user ) do |ssh|
ssh.sftp.connect do |sftp|
# upload local 'file' to remote 'rfile'
sftp.upload!(file, rfile)
# run remote command 'cmd' to produce 'rprod'
ssh.exec!(cmd)
# download remote 'rprod' to local 'prod'
sftp.download!(rprod, prod)
end
end
现在我的问题出在
ssh.exec!(cmd)
我想实时向本地用户显示 cmd 的输出。但是成功了
puts ssh.exec!(cmd)
我只在命令完成运行后才能得到结果输出。我将如何更改代码才能使其正常工作?
【问题讨论】:
标签: ruby command-line ssh