title: Ruby Net-SSH-Shell get standard out from execute! method
body: <p>How do I get stdout from the <code>.execute</code> method in Net-SSH-Shell</p>
  
  <p>With good 'ol Net-SSH, this is easy</p>
  
  <pre><code>Net::SSH.start('host','user') do |ssh|
       puts ssh.exec! 'date'
  end
  </code></pre>
  
  <p>Gives me <code>Tue Jun 19 23:43:53 EDT 2012</code></p>
  
  <p>but if I try to use a shell, I get a process object</p>
  
  <pre><code>Net::SSH.start('host','user') do |ssh|
      ssh.shell do |bash|
          output = bash.execute! 'ls'
          puts output
      end
  end
  </code></pre>
  
  <p>Gives me <code>#&lt;Net::SSH::Shell::Process:0x007fc809b541d0&gt;</code></p>
  
  <p>I can't find anything in the sparse docs about how to get standard out easily. There is the <code>on_output</code> method, but that doesn't seem to do anything for me if I use the <code>execute!</code> method</p>
  
  <p>I've also tried passing a block to <code>.execute!</code> like</p>
  
  <pre><code>bash.execute! 'ls' do |output|
      puts output
  end
  </code></pre>
  
  <p>but I still get a process <code>#&lt;Net::SSH::Shell::Process:0x007fc809b541d0&gt;</code></p>
  
  <p>I need the standard out in a variable that I can use and I need an actual stateful login shell, which barebones Net-SSH doesn't do to my knowledge. </p>
  
  <p>Any ideas?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Along the same ideas of <strong>@vikhyat</strong>'s suggestion, I tried</p>
  
  <pre><code> ssh.shell do |bash|
        process = bash.execute! 'ls'  do |a,b|
              # a is the process itself, b is the output
              puts [a,b]
              output = b
        end
   end
  </code></pre>
  
  <p>But <code>b</code> is always empty, even when I know the command returns results.</p>