class Coque::Sh

Attributes

args[R]
context[R]

Public Class Methods

new(context, args, stdin = nil, stdout = nil, stderr = nil) click to toggle source
# 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

Public Instance Methods

[](*new_args) click to toggle source
# File lib/coque/sh.rb, line 24
def [](*new_args)
  self.class.new(self.context, self.args + new_args)
end
clone() click to toggle source
# File lib/coque/sh.rb, line 12
def clone
  self.class.new(context, args, stdin, stdout, stderr)
end
get_result() click to toggle source
# 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() click to toggle source
# File lib/coque/sh.rb, line 20
def inspect
  to_s
end
to_s() click to toggle source
# File lib/coque/sh.rb, line 16
def to_s
  "<Coque::Sh #{args.join(" ")}>"
end