Class: Rubsh::RunningCommand
- Inherits:
-
Object
- Object
- Rubsh::RunningCommand
- Defined in:
- lib/rubsh/running_command.rb
Constant Summary collapse
- SPECIAL_KWARGS =
%i[ _in_data _in _out _err _err_to_out _capture _bg _env _timeout _cwd _ok_code _out_bufsize _err_bufsize _no_out _no_err _long_sep _long_prefix _pipeline ]
- SPECIAL_KWARGS_WITHIN_PIPELINE =
%i[ _env _cwd _long_sep _long_prefix _pipeline ]
Instance Attribute Summary collapse
- #exit_code ⇒ Number readonly
- #finished_at ⇒ Time readonly
- #pid ⇒ Number readonly
- #started_at ⇒ Time readonly
- #stderr_data ⇒ String readonly
- #stdout_data ⇒ String readonly
Instance Method Summary collapse
-
#initialize(sh, prog, progpath, *args, **kwargs) ⇒ RunningCommand
constructor
A new instance of RunningCommand.
- #ok? ⇒ Boolean
- #to_s ⇒ String
- #wait(timeout: nil) ⇒ void
- #wall_time ⇒ Numeric? (also: #execution_time)
Constructor Details
#initialize(sh, prog, progpath, *args, **kwargs) ⇒ RunningCommand
Returns a new instance of RunningCommand.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rubsh/running_command.rb', line 56 def initialize(sh, prog, progpath, *args, **kwargs) @sh = sh @prog = prog @progpath = progpath @args = [] # Runtime @prog_with_args = nil @pid = nil @exit_code = nil @started_at = nil @finished_at = nil @stdout_data = "".force_encoding(::Encoding.default_external) @stderr_data = "".force_encoding(::Encoding.default_external) @in_rd = nil @in_wr = nil @out_rd = nil @out_wr = nil @err_rd = nil @err_wr = nil @out_rd_reader = nil @err_rd_reader = nil # Special Kwargs - Controlling Input/Output @_in_data = nil @_in = nil @_out = nil @_err = nil @_err_to_out = false @_capture = nil # Special Kwargs - Execution @_bg = false @_env = nil @_timeout = nil @_cwd = nil @_ok_code = [0] # Special Kwargs - Performance & Optimization @_out_bufsize = 0 @_err_bufsize = 0 @_no_out = false @_no_err = false # Special Kwargs - Program Arguments @_long_sep = "=" @_long_prefix = "--" # Special Kwargs - Misc @_pipeline = nil opts = [] args.each do |arg| if arg.is_a?(::Hash) arg.each { |k, v| opts << Option.build(k, v) } else opts << Option.build(arg) end end kwargs.each { |k, v| opts << Option.build(k, v) } validate_opts(opts) extract_opts(opts) end |
Instance Attribute Details
#exit_code ⇒ Number (readonly)
38 39 40 |
# File 'lib/rubsh/running_command.rb', line 38 def exit_code @exit_code end |
#finished_at ⇒ Time (readonly)
46 47 48 |
# File 'lib/rubsh/running_command.rb', line 46 def finished_at @finished_at end |
#pid ⇒ Number (readonly)
34 35 36 |
# File 'lib/rubsh/running_command.rb', line 34 def pid @pid end |
#started_at ⇒ Time (readonly)
42 43 44 |
# File 'lib/rubsh/running_command.rb', line 42 def started_at @started_at end |
#stderr_data ⇒ String (readonly)
54 55 56 |
# File 'lib/rubsh/running_command.rb', line 54 def stderr_data @stderr_data end |
#stdout_data ⇒ String (readonly)
50 51 52 |
# File 'lib/rubsh/running_command.rb', line 50 def stdout_data @stdout_data end |
Instance Method Details
#ok? ⇒ Boolean
127 128 129 |
# File 'lib/rubsh/running_command.rb', line 127 def ok? @_ok_code.include?(@exit_code) end |
#to_s ⇒ String
138 139 140 |
# File 'lib/rubsh/running_command.rb', line 138 def to_s @prog_with_args end |
#wait(timeout: nil) ⇒ void
This method returns an undefined value.
132 133 134 135 |
# File 'lib/rubsh/running_command.rb', line 132 def wait(timeout: nil) wait2(timeout: timeout) handle_return_code end |
#wall_time ⇒ Numeric? Also known as: execution_time
121 122 123 |
# File 'lib/rubsh/running_command.rb', line 121 def wall_time @finished_at.nil? ? nil : @finished_at - @started_at end |