Class: SSH::Ident::ShellCmd
- Inherits:
-
Object
- Object
- SSH::Ident::ShellCmd
- Defined in:
- lib/ssh/ident/shell_cmd.rb
Overview
runs a shell command [in the context of the agent]
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#own_env ⇒ Object
readonly
Returns the value of attribute own_env.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ShellCmd
constructor
A new instance of ShellCmd.
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ShellCmd
Returns a new instance of ShellCmd.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ssh/ident/shell_cmd.rb', line 10 def initialize( = {}) fail 'command not set' unless .key?(:command) @command = [:command] @own_env = [:own_env] @quote_command = [:quote_command] @quote_command ||= true @agent_file = [:agent_file] @output = [:output] @own_env = true if @agent_file end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
8 9 10 |
# File 'lib/ssh/ident/shell_cmd.rb', line 8 def command @command end |
#own_env ⇒ Object (readonly)
Returns the value of attribute own_env.
8 9 10 |
# File 'lib/ssh/ident/shell_cmd.rb', line 8 def own_env @own_env end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
8 9 10 |
# File 'lib/ssh/ident/shell_cmd.rb', line 8 def result @result end |
Instance Method Details
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ssh/ident/shell_cmd.rb', line 21 def run command = @command.dup cmd = [] cmd << '/usr/bin/env' << '-i' if @own_env command = ". #{@agent_file} > /dev/null 2>/dev/null; #{command}" if @agent_file command = "\"#{command}\"" if @quote_command cmd << '/bin/sh' << "-c #{command}" cmd << '>/dev/null' << '2>/dev/null' unless @output full_command = cmd.join(' ') # puts "running: #{full_command}" @result = `#{full_command}` @result = nil if $CHILD_STATUS.to_i != 0 @result end |