From: Oddly Zen Date: 2009-12-15T05:16:08+09:00 Subject: Re: Working with a command-line application on a remote server via Net::SSH On Dec 14, 12:23 pm, Oddly Zen wrote: > How do I send the data once the application is invoked on the remote > machine, wait for the response (checking that against possible > responses), then send more data, and repeat until all the options are > sent, until I get the final output from the application? Well, I'll answer my own question for historical purposes. I found that Net::SSH::Connection::Session#open_channel to do exactly what I need. I can then pass in a block and use the #on_data callback to interact with my remote command-line application. The code now looks somewhat like: Net::SSH.start(@server, @user, :password => @pass) do |ssh| ssh.open_channel do |channel| channel.exec "./solve -iy -c /path/to/config/file" do |ch, success| abort "Could not execute command!" unless success channel.on_data do |ch, data| puts "got stdout: #{data}" channel.send_data "li\n" puts "got stdout: #{data}" channel.send_data "etc.\n" ... end end end #ssh.loop -- bleck! end I am sure that I can clean this up now by queueing up the data to be sent and waiting on the response rather than just cycling through all this in a loop like it does now. Any suggestions for this pattern?