0

In my Project, I have to execute a command in remote machine. and also i have to capture and display the output of the command in realtime. for example, If i am running 'dir' command in remote machine,then i should display how many minutes it requires to execute( like 2 mins remaining) the command.

Kamesh
  • 1,435
  • 1
  • 14
  • 27

2 Answers2

1

You can try using the ruby-progressbar gem and place the output in a file that you can read

require 'ruby-progressbar'
p = ProgressBar.create(:format => '%a %B %p%% %t')
=> #<ProgressBar:0/100>           

 def test(p)
    d = Dir.new('ank')
    d.each do |file|
      sleep 4
      puts file
      p.increment
    end
end
=> nil 


1.9.3-p545 :029 > test(p)
.
..me: 00:00:06 =1% Progress                                                                                                    
bare:                                          00:00:10 == 2% Progress                                                                                                  
baze:                                        00:00:14 === 3% Progress                                                                                                
fooe:                                       00:00:18 ==== 4% Progress                                                                                               
 => #<Dir:ank> =====                                                                                                5% Progress
AnkitG
  • 6,438
  • 7
  • 44
  • 72
0

Take a look at this, i guess it answers at least one of your questions

But I don't know for sure how to easily provide you with the execution time of that command

You may probably need to run all possible commands to estimate their execution time first, and put that data in some storage (database for example).

Or you can create table to store that time and grow that table after each command execution, so when the user tries to run a command already existant in that table, you give the user time estimated last time it was run;

Community
  • 1
  • 1
Bogdan Agafonov
  • 157
  • 1
  • 9