Class: Sevgi::Function::Shell::Runner Private

Inherits:
Object
  • Object
show all
Defined in:
lib/sevgi/function/shell.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Runs shell commands and captures stdout, stderr, and exit status.

Instance Method Summary collapse

Constructor Details

#initializevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a shell runner.



81
82
83
# File 'lib/sevgi/function/shell.rb', line 81

def initialize
  @coathooks = 0
end

Instance Method Details

#call(*args) { ... } ⇒ Sevgi::Function::Shell::Result

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs a command and captures its output.

Parameters:

  • args (Array<String>)

    command and arguments

Yields:

  • optional content writer for stdin

Yield Returns:

Returns:

Raises:

  • (Errno::ENOENT)

    when the executable cannot be spawned



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/sevgi/function/shell.rb', line 91

def call(*args, &input)
  return Result.dummy if args.empty?

  outs, errs, status = Open3.popen3(*args) do |stdin, stdout, stderr, wait_thread|
    content = input.call if input
    stdin.write(content) if content
    stdin.close

    capture(stdout, stderr, wait_thread)
  end

  Result.new(args, outs, errs, status.exitstatus)
end