Class: ThorSsh::LocalServer
- Inherits:
-
Object
- Object
- ThorSsh::LocalServer
- Defined in:
- lib/thor-ssh/local_server.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
Instance Method Summary collapse
-
#initialize(base) ⇒ LocalServer
constructor
A new instance of LocalServer.
- #run(command, options = {}) ⇒ Object
-
#run_with_codes(command) ⇒ Object
TODO: This should inherit from the same thing as RemoteServer and it should have the same run but different run_with_codes.
Constructor Details
#initialize(base) ⇒ LocalServer
Returns a new instance of LocalServer.
7 8 9 |
# File 'lib/thor-ssh/local_server.rb', line 7 def initialize(base) @base = base end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
5 6 7 |
# File 'lib/thor-ssh/local_server.rb', line 5 def base @base end |
Instance Method Details
#run(command, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/thor-ssh/local_server.rb', line 32 def run(command, ={}) if [:with_codes] return run_with_codes(command) else stdout, stdin, exit_code, exit_signal = run_with_codes(command) return stdout end end |
#run_with_codes(command) ⇒ Object
TODO: This should inherit from the same thing as RemoteServer and it should have the same run but different run_with_codes
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/thor-ssh/local_server.rb', line 13 def run_with_codes(command) # pid, stdin, stdout, stderr = Open4::popen4(command) # ignored, status = Process::waitpid2 pid # exit_code = status.to_i exit_signal = nil stdout_data = '' stderr_data = '' status = POpen4::popen4(command) do |stdout, stderr, stdin, pid| stdin.close stdout_data = stdout.read stderr_data = stderr.read.strip end exit_code = status ? status.exitstatus : 0 return stdout_data, stderr_data, exit_code, exit_signal end |