简体   繁体   中英

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!

What's going on??

I suppose to delete file you should use rm command. Like that

   ch.exec("rm filename.mp4") do |tk, success|

From the Net::SSH docs for Channel#exec

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM