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

  • Home
  • SEARCH
  • 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 229837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:47:57+00:00 2026-05-11T19:47:57+00:00

I’ve got a script thats supposed to mimic ffmpeg on my local machine, by

  • 0

I’ve got a script thats supposed to mimic ffmpeg on my local machine, by sending the command of to a remote machine, running it there and then returning the results.
(see previous stackoverflow question.)

#!/usr/bin/env ruby

require 'rubygems'
require 'net/ssh'
require 'net/sftp'
require 'highline/import'


file = ARGV[ ARGV.index( '-i' ) + 1] if ARGV.include?( '-i' )  
puts 'No input file specified' unless file;

host = "10.0.0.10"
user = "user"
prod = "new-#{file}"               # product filename (call it <file>-new)
rpath = "/home/#{user}/.rffmpeg"   # remote computer operating directory
rfile = "#{rpath}/#{file}"         # remote filename
rprod = "#{rpath}/#{prod}"         # remote product
cmd = "ffmpeg -i #{rfile} #{rprod}"# remote command, constructed

pass = ask("Password: ") { |q| q.echo = false }  # password from stdin

Net::SSH.start(host, user ) do |ssh|
        ssh.sftp.connect do |sftp|

                # upload local 'file' to remote 'rfile'
                sftp.upload!(file, rfile)

                # run remote command 'cmd' to produce 'rprod'
                ssh.exec!(cmd)

                # download remote 'rprod' to local 'prod'
                sftp.download!(rprod, prod)
        end
end

now my problem is at

ssh.exec!(cmd)

I want to display the cmd’s output to the local user in real-time. But making it

puts ssh.exec!(cmd)

I only get the resulting output after the command has finished running. How would I have to change the code to make this work?

  • 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-05-11T19:47:57+00:00Added an answer on May 11, 2026 at 7:47 pm

    From ri Net::SSH::start:

     -------------------------------------------------------- Net::SSH::start
          Net::SSH::start(host, user, options={}, &block) {|connection| ...}
     ------------------------------------------------------------------------
          The standard means of starting a new SSH connection. When used with
          a block, the connection will be closed when the block terminates,
          otherwise the connection will just be returned. The yielded (or
          returned) value will be an instance of
          Net::SSH::Connection::Session (q.v.). (See also
          Net::SSH::Connection::Channel and Net::SSH::Service::Forward.)
    
            Net::SSH.start("host", "user") do |ssh|
              ssh.exec! "cp /some/file /another/location"
              hostname = ssh.exec!("hostname")
    
              ssh.open_channel do |ch|
                ch.exec "sudo -p 'sudo password: ' ls" do |ch, success|
                  abort "could not execute sudo ls" unless success
    
                  ch.on_data do |ch, data|
                    print data
                    if data =~ /sudo password: /
                      ch.send_data("password\n")
                    end
                  end
                end
              end
    
              ssh.loop
            end
    

    So it looks like you can get more interactive by using #open_channel

    Here’s some example code:

    user@server% cat echo.rb
    #! /usr/local/bin/ruby
    def putsf s
      puts s
      STDOUT.flush
    end
    putsf "hello"
    5.times do
            putsf gets.chomp
    end
    putsf "goodbye"
    

    And on your local machine:

    user@local% cat client.rb
    #! /usr/local/bin/ruby
    require 'rubygems'
    require 'net/ssh'
    words = %w{ earn more sessions by sleaving }
    index = 0;
    Net::SSH.start('server', 'user') do |ssh|
      ssh.open_channel do |ch|
        ch.exec './echo.rb' do |ch, success|
          abort "could not execute ./echo.rb" unless success
    
          ch.on_data do |ch, data|
            p [:data, data]
            index %= words.size
            ch.send_data( words[index] + "\n" )
            index += 1
          end
        end
      end
    end
    user@local% ./client.rb
    [:data, "hello\n"]
    [:data, "earn\n"]
    [:data, "more\n"]
    [:data, "sessions\n"]
    [:data, "by\n"]
    [:data, "sleaving\n"]
    [:data, "goodbye\n"]
    

    So you can interact with a running process this way.

    It’s important that the running process flush its output before requesting input – otherwise, the program might hang as the channel may not have received the unflushed output.

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

Sidebar

Ask A Question

Stats

  • Questions 231k
  • Answers 231k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use the following function like this: Image('/path/to/original.image', '1/1', '150*', './thumb.jpg');… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer Check you database schema to see if the field (referenced… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer I figured out the problem - there was a session… May 13, 2026 at 2:13 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS
I want use html5's new tag to play a wav file (currently only supported

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.