Class: Coque::Sh
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Attributes included from Redirectable
Instance Method Summary collapse
- #[](*new_args) ⇒ Object
- #clone ⇒ Object
- #get_result ⇒ Object
-
#initialize(context, args, stdin = nil, stdout = nil, stderr = nil) ⇒ Sh
constructor
A new instance of Sh.
- #inspect ⇒ Object
- #to_s ⇒ Object
Methods inherited from Cmd
Methods included from Runnable
#log_start, #run, #run!, #success?, #to_a, #to_a!
Methods included from Redirectable
#<, #>, #>=, #err, #getio, #in, #out
Constructor Details
#initialize(context, args, stdin = nil, stdout = nil, stderr = nil) ⇒ Sh
Returns a new instance of Sh.
4 5 6 7 8 9 10 |
# File 'lib/coque/sh.rb', line 4 def initialize(context, args, stdin = nil, stdout = nil, stderr = nil) @context = context @args = args self.stdin = stdin if stdin self.stdout = stdout if stdout self.stderr = stderr if stderr end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
3 4 5 |
# File 'lib/coque/sh.rb', line 3 def args @args end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/coque/sh.rb', line 3 def context @context end |
Instance Method Details
#[](*new_args) ⇒ Object
24 25 26 |
# File 'lib/coque/sh.rb', line 24 def [](*new_args) self.class.new(self.context, self.args + new_args) end |
#clone ⇒ Object
12 13 14 |
# File 'lib/coque/sh.rb', line 12 def clone self.class.new(context, args, stdin, stdout, stderr) end |
#get_result ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/coque/sh.rb', line 28 def get_result stdin, stdoutr, stdoutw = get_default_fds opts = {in: stdin, stdin.fileno => stdin.fileno, out: stdoutw, stdoutw.fileno => stdoutw.fileno, chdir: context.dir, unsetenv_others: context.disinherits_env?} # Redirect err to out: (e.g. for 2>&1) # {err: [:child, :out]} err_opts = if stderr {err: stderr, stderr.fileno => stderr.fileno} else {} end pid = spawn(context.env, args.join(" "), opts.merge(err_opts)) stdoutw.close Result.new(pid, stdoutr) end |
#inspect ⇒ Object
20 21 22 |
# File 'lib/coque/sh.rb', line 20 def inspect to_s end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/coque/sh.rb', line 16 def to_s "<Coque::Sh #{args.join(" ")}>" end |