Class: Sahara::Shell
- Inherits:
-
Object
- Object
- Sahara::Shell
- Defined in:
- lib/sahara/shell.rb
Class Method Summary collapse
- .execute(command, options = {}) ⇒ Object
-
.execute2(command, options = {}) ⇒ Object
pty allows you to gradually see the output of a local command www.shanison.com/?p=415.
-
.execute3(command, options = {}) ⇒ Object
occassinally fails with ‘no child processes.
Class Method Details
.execute(command, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/sahara/shell.rb', line 6 def self.execute(command, = {}) STDOUT.sync = true output=nil result=IO.popen("#{command}") {|f| output=f.readlines} #{ |f| print "#{f}, #{f.class}" } # output=result.read return output end |
.execute2(command, options = {}) ⇒ Object
pty allows you to gradually see the output of a local command www.shanison.com/?p=415
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sahara/shell.rb', line 17 def self.execute2(command, = {} ) require "pty" begin PTY.spawn( command ) do |r, w, pid| begin #r.each { } r.each { |line| print line;} rescue Errno::EIO end end rescue PTY::ChildExited => e puts "The child process exited!" end end |
.execute3(command, options = {}) ⇒ Object
occassinally fails with ‘no child processes
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/sahara/shell.rb', line 34 def self.execute3(command, = {} ) defaults= { :port => "22", :exitcode => "0", :user => "root"} =defaults.merge() status = POpen4::popen4(command) do |stdout,stderr,stdin| stdout.each do |line| puts line end end @status=status.to_i if (@status.to_s != [:exitcode] ) if ([:exitcode]=="*") #its a test so we don't need to worry else raise "Exitcode was not what we expected" end end end |