Class: SHExecutor::Executor
- Inherits:
-
Object
- Object
- SHExecutor::Executor
- Defined in:
- lib/shexecutor.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Instance Method Summary collapse
- #execute ⇒ Object
- #flush ⇒ Object
-
#initialize(options = ::SHExecutor::default_options) ⇒ Executor
constructor
A new instance of Executor.
- #status ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(options = ::SHExecutor::default_options) ⇒ Executor
Returns a new instance of Executor.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/shexecutor.rb', line 56 def initialize( = ::SHExecutor::) # set default options @options = ::SHExecutor::.dup # then apply specified options .each do |key, value| @options[key] = value end @options end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
45 46 47 |
# File 'lib/shexecutor.rb', line 45 def @options end |
#result ⇒ Object
Returns the value of attribute result.
49 50 51 |
# File 'lib/shexecutor.rb', line 49 def result @result end |
#stderr ⇒ Object
Returns the value of attribute stderr.
44 45 46 |
# File 'lib/shexecutor.rb', line 44 def stderr @stderr end |
#stdout ⇒ Object
Returns the value of attribute stdout.
43 44 45 |
# File 'lib/shexecutor.rb', line 43 def stdout @stdout end |
Instance Method Details
#execute ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/shexecutor.rb', line 97 def execute @pid = nil @stdout = nil @stderr = nil if (@options[:replace] == true) replace_process else if (@options[:wait_for_completion]) if (@options[:timeout] <= 0) block_process else block_process_with_timeout end else fork_process end end end |
#flush ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/shexecutor.rb', line 116 def flush return nil if @data_out.nil? or @data_err.nil? stdout_data = @data_out.string stderr_data = @data_err.string @stdout = stdout_data if stdout_data != "" @stderr = stderr_data if stderr_data != "" stdout_to_file if (@options[:stdout_path]) stderr_to_file if (@options[:stderr_path]) end |
#status ⇒ Object
68 69 70 71 72 |
# File 'lib/shexecutor.rb', line 68 def status return "not executed" if @result.nil? return @result.status if @result.alive? return "no longer executing" if not @result.alive? end |
#validate ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/shexecutor.rb', line 79 def validate errors = [] if (@options[:protect_against_injection]) and (!@options[:application_path].nil? and @options[:application_path].strip != "") if (File.exists?(@options[:application_path])) errors << "Application path not executable" if !File.executable?(@options[:application_path]) else errors << "Application path not found" end errors << "Suspected injection vulnerability due to space in application_path or the object being marked as 'tainted' by Ruby. Turn off strict checking if you are sure by setting :protect_against_injection to false" if possible_injection?(@options[:application_path]) else errors << "No application path provided" if (@options[:application_path].nil?) or (@options[:application_path].strip == "") end raise ArgumentError.new(errors.join(',')) if errors.count > 0 end |