[英]Ruby Net::SSH will not give result of executed command
Here is my code 这是我的代码
Net::SSH.start("XXX.upload.akamai.com", "sshacs", :keys=>["#{ENV['AKAMAI_SSH_KEY']}"]) do |mk|
channel = mk.open_channel do |ch|
ch.exec("rm filename.mp4") do |tk, success|
if success
puts "++++++++++++ Deleted: #{success.class}"
else
puts "------------ NOT deleted: #{success.class}"
end
end
end
end
success
is always True eventhough the file I want to remove does not even exist! 即使我要删除的文件甚至不存在, success
也总是True!
What's going on?? 这是怎么回事??
I suppose to delete file you should use rm command. 我想删除文件,您应该使用rm命令。 Like that 像那样
ch.exec("rm filename.mp4") do |tk, success|
From the Net::SSH docs for Channel#exec 从网上:: Channel#exec的SSH文档
In this case, success means that the command is being executed, not that it has completed,... 在这种情况下,成功意味着命令正在执行,而不是命令已经完成,...
I'm wondering if you're getting success because it is successfully sending a request, and Net::SSH doesn't care if that request is complete or not. 我想知道您是否成功,因为它成功发送了一个请求,而Net :: SSH不在乎该请求是否完成。 It did it's job, so it's a success. 它做到了,所以成功了。
combine it with something like: on data 将其与类似以下内容结合: 关于数据
channel.on_data do |ch, data|
puts "what am i really getting back: #{data.inspect}"
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.