Method: Net::SSH::Connection::Channel#exec
- Defined in:
- lib/net/ssh/connection/channel.rb
#exec(command, &block) ⇒ Object
Syntactic sugar for executing a command. Sends a channel request asking that the given command be invoked. If the block is given, it will be called when the server responds. The first parameter will be the channel, and the second will be true or false, indicating whether the request succeeded or not. In this case, success means that the command is being executed, not that it has completed, and failure means that the command altogether failed to be executed.
channel.exec "ls -l /home" do |ch, success|
if success
puts "command has begun executing..."
# this is a good place to hang callbacks like #on_data...
else
puts "alas! the command could not be invoked!"
end
end
158 159 160 |
# File 'lib/net/ssh/connection/channel.rb', line 158 def exec(command, &block) send_channel_request("exec", :string, command, &block) end |