Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7837011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:25:54+00:00 2026-06-02T14:25:54+00:00

I have a function def run_through_ssh(command) host = $edumate_server user = ‘user’ pass =

  • 0

I have a function

def run_through_ssh(command)
    host = $edumate_server
    user = 'user'
    pass = '******'

    output = Array.new      
    Net::SSH.start( host, user, :password => pass ) do|ssh|
        output = ssh.exec(command)
        #output = ssh.exec(command+" 2>&1")
    end

    return output
end

which executes the command I want correctly on the remote server but the output variable doesn’t contain what the remotely executed command outputs to the screen. I use this function inside sinatra and strangely I can see the output on the screen where I run sinatra.

How can I capture the output of remotely executed command?

The output variable contains things like

#<Net::SSH::Connection::Channel:0x3fe40c0 @remote_maximum_window_size=2097152, @
eof=false, @on_open_failed=nil, @remote_window_size=2097152, @closing=true, @pro
perties={}, @local_maximum_packet_size=65536, @on_process=nil, @type="session",
@remote_id=0, @on_confirm_open=#<Proc:0x031f64a0@C:/Ruby187/lib/ruby/gems/1.8/ge
ms/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:320>, @on_request={}, @local_
id=0, @on_extended_data=#<Proc:0x031f6560@C:/Ruby187/lib/ruby/gems/1.8/gems/net-
ssh-2.2.1/lib/net/ssh/connection/session.rb:332>, @local_maximum_window_size=131
072, @on_eof=nil, @connection=#<Net::SSH::Connection::Session:0x3fe42a0 @options
={:logger=>#<Logger:0x400cb90 @level=4, @progname=nil, @logdev=#<Logger::LogDevi

using

  • ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
  • net-ssh (2.2.1)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:25:55+00:00Added an answer on June 2, 2026 at 2:25 pm

    Something like this should work:

    Net::SSH.start( host, user, :password => pass ) do |ssh|
      output = ssh.exec!(command)
    end
    output
    

    The exec! method captures stdin/stdout if no block is given. See http://net-ssh.github.com/ssh/v2/api/classes/Net/SSH/Connection/Session.html#M000094

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function: def create(sender, **kw): [...] Which should be called when the
I have a function foo that accepts a Boolean function def foo( f:(_)=>Boolean )
I am writing a script and in my script I have this function: def
In python I have the following function: def is_a_nice_element(element, parameter): #do something return True
I have a function like this: def eventcateg_detail(request): ca = EventTypeCategory.objects.values() for i in
I have this function in Python: def Rotate_Vector(vector, axis, direction): where vector is a
I have a function that accepts wildcard keyword parameters: def func(**kargs): doA doB How
I have a function which returns 3 numbers, e.g.: def numbers(): return 1,2,3 usually
I have a decorated function (simplified version): class Memoize: def __init__(self, function): self.function =
I have used this function to convert string to bits. def a2bits(chars): return bin(reduce(lambda

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.