Class: Sprout::ProcessRunner
- Inherits:
-
Object
- Object
- Sprout::ProcessRunner
- Defined in:
- lib/sprout/process_runner.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#e ⇒ Object
readonly
Returns the value of attribute e.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#r ⇒ Object
readonly
Returns the value of attribute r.
-
#w ⇒ Object
readonly
Returns the value of attribute w.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #close ⇒ Object
- #close_write ⇒ Object
- #flush ⇒ Object
- #getc ⇒ Object
-
#initialize(*command) ⇒ ProcessRunner
constructor
A new instance of ProcessRunner.
- #kill ⇒ Object
- #print(msg) ⇒ Object
- #puts(msg) ⇒ Object
- #read ⇒ Object
- #read_err ⇒ Object
- #readlines ⇒ Object
- #readpartial(count) ⇒ Object
- #update_executable_mode(*command) ⇒ Object
- #update_status ⇒ Object
Constructor Details
#initialize(*command) ⇒ ProcessRunner
Returns a new instance of ProcessRunner.
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 |
# File 'lib/sprout/process_runner.rb', line 12 def initialize(*command) @command = command begin @alive = true usr = User.new() if(usr.is_a?(WinUser) && !usr.is_a?(CygwinUser)) gem 'win32-open3' require 'win32/open3' Open3.popen3(*@command) do |w, r, e, pid| @w = w @r = r @e = e @pid = pid end else require 'open4' @pid, @w, @r, @e = open4.popen4(*@command) end rescue Errno::EACCES => e update_executable_mode(*@command) @pid, @w, @r, @e = open4.popen4(*@command) rescue Errno::ENOENT => e @alive = false part = command[0].split(' ').shift raise ProcessRunnerError.new("The expected executable was not found for command [#{part}], please check your system path and/or sprout definition") end end |
Instance Attribute Details
#e ⇒ Object (readonly)
Returns the value of attribute e.
7 8 9 |
# File 'lib/sprout/process_runner.rb', line 7 def e @e end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
7 8 9 |
# File 'lib/sprout/process_runner.rb', line 7 def pid @pid end |
#r ⇒ Object (readonly)
Returns the value of attribute r.
7 8 9 |
# File 'lib/sprout/process_runner.rb', line 7 def r @r end |
#w ⇒ Object (readonly)
Returns the value of attribute w.
7 8 9 |
# File 'lib/sprout/process_runner.rb', line 7 def w @w end |
Instance Method Details
#alive? ⇒ Boolean
53 54 55 |
# File 'lib/sprout/process_runner.rb', line 53 def alive? @alive = update_status end |
#close ⇒ Object
61 62 63 |
# File 'lib/sprout/process_runner.rb', line 61 def close update_status end |
#close_write ⇒ Object
99 100 101 |
# File 'lib/sprout/process_runner.rb', line 99 def close_write @w.close_write end |
#flush ⇒ Object
83 84 85 |
# File 'lib/sprout/process_runner.rb', line 83 def flush @w.flush end |
#getc ⇒ Object
87 88 89 |
# File 'lib/sprout/process_runner.rb', line 87 def getc @r.getc end |
#kill ⇒ Object
57 58 59 |
# File 'lib/sprout/process_runner.rb', line 57 def kill Process.kill(9, pid) end |
#print(msg) ⇒ Object
91 92 93 |
# File 'lib/sprout/process_runner.rb', line 91 def print(msg) @w.print msg end |
#puts(msg) ⇒ Object
95 96 97 |
# File 'lib/sprout/process_runner.rb', line 95 def puts(msg) @w.puts(msg) end |
#read ⇒ Object
103 104 105 |
# File 'lib/sprout/process_runner.rb', line 103 def read return @r.read end |
#read_err ⇒ Object
107 108 109 |
# File 'lib/sprout/process_runner.rb', line 107 def read_err return @e.read end |
#readlines ⇒ Object
79 80 81 |
# File 'lib/sprout/process_runner.rb', line 79 def readlines @r.readlines end |
#readpartial(count) ⇒ Object
75 76 77 |
# File 'lib/sprout/process_runner.rb', line 75 def readpartial(count) @r.readpartial(count) end |
#update_executable_mode(*command) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sprout/process_runner.rb', line 40 def update_executable_mode(*command) parts = command.join(' ').split(' ') str = parts.shift while(parts.size > 0) if(File.exists?(str)) FileUtils.chmod(744, str) return else str << " #{parts.shift}" end end end |
#update_status ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/sprout/process_runner.rb', line 65 def update_status pid_int = Integer("#{ @pid }") begin Process::kill 0, pid_int true rescue Errno::ESRCH false end end |