Class: Net::SSH::Shell::Process
- Inherits:
-
Object
- Object
- Net::SSH::Shell::Process
- Defined in:
- lib/net/ssh/shell/process.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#exit_status ⇒ Object
readonly
Returns the value of attribute exit_status.
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #busy? ⇒ Boolean
- #finished? ⇒ Boolean
-
#initialize(manager, command, properties, callback) ⇒ Process
constructor
A new instance of Process.
- #on_error_output(&callback) ⇒ Object
- #on_finish(&callback) ⇒ Object
- #on_output(&callback) ⇒ Object
- #run ⇒ Object
- #running? ⇒ Boolean
- #send_data(data) ⇒ Object
- #starting? ⇒ Boolean
- #wait! ⇒ Object
Constructor Details
#initialize(manager, command, properties, callback) ⇒ Process
Returns a new instance of Process.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/net/ssh/shell/process.rb', line 10 def initialize(manager, command, properties, callback) @command = command @manager = manager @callback = callback @properties = properties @on_output = nil @on_error_output = nil @on_finish = nil @state = :new end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
6 7 8 |
# File 'lib/net/ssh/shell/process.rb', line 6 def callback @callback end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
4 5 6 |
# File 'lib/net/ssh/shell/process.rb', line 4 def command @command end |
#exit_status ⇒ Object (readonly)
Returns the value of attribute exit_status.
7 8 9 |
# File 'lib/net/ssh/shell/process.rb', line 7 def exit_status @exit_status end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
5 6 7 |
# File 'lib/net/ssh/shell/process.rb', line 5 def manager @manager end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
8 9 10 |
# File 'lib/net/ssh/shell/process.rb', line 8 def properties @properties end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
3 4 5 |
# File 'lib/net/ssh/shell/process.rb', line 3 def state @state end |
Instance Method Details
#[](key) ⇒ Object
21 22 23 |
# File 'lib/net/ssh/shell/process.rb', line 21 def [](key) @properties[key] end |
#[]=(key, value) ⇒ Object
25 26 27 |
# File 'lib/net/ssh/shell/process.rb', line 25 def []=(key, value) @properties[key] = value end |
#busy? ⇒ Boolean
67 68 69 |
# File 'lib/net/ssh/shell/process.rb', line 67 def busy? starting? || running? end |
#finished? ⇒ Boolean
63 64 65 |
# File 'lib/net/ssh/shell/process.rb', line 63 def finished? state == :finished end |
#on_error_output(&callback) ⇒ Object
80 81 82 |
# File 'lib/net/ssh/shell/process.rb', line 80 def on_error_output(&callback) @on_error_output = callback end |
#on_finish(&callback) ⇒ Object
84 85 86 |
# File 'lib/net/ssh/shell/process.rb', line 84 def on_finish(&callback) @on_finish = callback end |
#on_output(&callback) ⇒ Object
76 77 78 |
# File 'lib/net/ssh/shell/process.rb', line 76 def on_output(&callback) @on_output = callback end |
#run ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/net/ssh/shell/process.rb', line 33 def run if state == :new state = :starting manager.open do state = :running manager.channel.on_data(&method(:on_stdout)) manager.channel.on_extended_data(&method(:on_stderr)) manager.channel.on_close(&method(:on_close)) callback.call(self) if callback cmd = command.dup cmd << ";" if cmd !~ /[;&]$/ cmd << " DONTEVERUSETHIS=$?; echo #{manager.separator} $DONTEVERUSETHIS; echo \"exit $DONTEVERUSETHIS\"|sh" send_data(cmd + "\n") end end self end |
#running? ⇒ Boolean
59 60 61 |
# File 'lib/net/ssh/shell/process.rb', line 59 def running? state == :running end |
#send_data(data) ⇒ Object
29 30 31 |
# File 'lib/net/ssh/shell/process.rb', line 29 def send_data(data) manager.channel.send_data(data) end |
#starting? ⇒ Boolean
55 56 57 |
# File 'lib/net/ssh/shell/process.rb', line 55 def starting? state == :starting end |
#wait! ⇒ Object
71 72 73 74 |
# File 'lib/net/ssh/shell/process.rb', line 71 def wait! manager.session.loop { busy? } self end |