Class: Shellshot::Command
- Inherits:
-
Object
- Object
- Shellshot::Command
- Defined in:
- lib/shellshot.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
1 hour
60 * 60
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #exec(command, options = {}) ⇒ Object
- #stderr_contents ⇒ Object
- #stdout_contents ⇒ Object
- #system_exec ⇒ Object
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
15 16 17 |
# File 'lib/shellshot.rb', line 15 def @options end |
#pid ⇒ Object
Returns the value of attribute pid.
15 16 17 |
# File 'lib/shellshot.rb', line 15 def pid @pid end |
#status ⇒ Object
Returns the value of attribute status.
15 16 17 |
# File 'lib/shellshot.rb', line 15 def status @status end |
Instance Method Details
#exec(command, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/shellshot.rb', line 17 def exec(command, = {}) self. = timeout = [:timeout] || DEFAULT_TIMEOUT prepare_pipes self.pid = fork do close_reading_pipes redefine_stds system_exec(*command) end begin wait_for(timeout) rescue Timeout::Error => e terminate_child_process raise Timeout::Error, "execution of #{command} exceeded #{timeout} seconds" end true end |
#stderr_contents ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/shellshot.rb', line 39 def stderr_contents @stderr_contents ||= unless stderr_defined? @stderr_wr.close contents = @stderr_rd.read @stderr_rd.close contents else File.read(stderr_location) end end |
#stdout_contents ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/shellshot.rb', line 50 def stdout_contents @stdout_contents ||= unless stdout_defined? @stdout_wr.close contents = @stdout_rd.read @stdout_rd.close contents else File.read(stdout_location) end end |
#system_exec ⇒ Object
11 |
# File 'lib/shellshot.rb', line 11 alias_method :system_exec, :exec |