Class: Releasinator::CommandProcessor
- Inherits:
-
Object
- Object
- Releasinator::CommandProcessor
- Defined in:
- lib/command_processor.rb
Class Method Summary collapse
- .command(command, live_output = false) ⇒ Object
-
.wait_for(command_to_execute, wait_for_seconds = 30) ⇒ Object
waits for the input command to return non-empty output.
Class Method Details
.command(command, live_output = false) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/command_processor.rb', line 6 def self.command(command, live_output=false) puts Time.now.utc.iso8601 + ": " + "#{Dir.pwd}".bold + " exec:" + " #{command}".bold if live_output puts "...with live output (forked process)".bold return_code = nil r, io = IO.pipe pid = fork do return_code = system(command, :out => io, :err => io) if !return_code Printer.fail("Execution failure.") abort() end end io.close output = "" r.each_line do |line| puts line.strip.white output << line end Process.wait(pid) fork_exitstatus = $?.exitstatus if 0 != fork_exitstatus Printer.fail("Forked process failed with exitstatus:#{fork_exitstatus}") abort() end else output = `#{command}` exitstatus = $?.exitstatus if 0 != exitstatus Printer.fail("Process failed with exitstatus:#{exitstatus}") abort() end end output end |
.wait_for(command_to_execute, wait_for_seconds = 30) ⇒ Object
waits for the input command to return non-empty output.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/command_processor.rb', line 46 def self.wait_for(command_to_execute, wait_for_seconds=30) while "" == CommandProcessor.command(command_to_execute) puts "Returned empty output. Sleeping #{wait_for_seconds} seconds." wait_for_seconds.times do print "." sleep 1 end puts end Printer.success("Returned non-empty output.") end |