Module: FPM::Fry::Exec

Defined in:
lib/fpm/fry/exec.rb

Defined Under Namespace

Classes: Failed

Class Method Summary collapse

Class Method Details

.[](*cmd, options = {}) ⇒ String Also known as: exec

Returns stdout.

Parameters:

  • cmd (Array<String>)

    command to run

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :logger (Cabin::Channel)
  • :description (String)

    human readable string to describe what the command is doing

  • :stdin_data (String)

    data to write to stding

  • :chdir (String)

    directory to change to

Returns:

  • (String)

    stdout

Raises:



30
31
32
33
34
35
36
37
# File 'lib/fpm/fry/exec.rb', line 30

def [](*args)
  cmd, options, description = extract_options_and_log(args)
  stdout, stderr, status = Open3.capture3(*cmd, options)
  if status.exitstatus != 0
    raise Exec.const_get("ExitCode#{status.exitstatus}").new("#{description} failed", exitstatus: status.exitstatus, stderr: stderr, stdout: stdout, command: cmd)
  end
  return stdout
end

.popen(*cmd, options = {}) ⇒ IO

Returns stdout.

Parameters:

  • cmd (Array<String>)

    command to run

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :logger (Cabin::Channel)
  • :description (String)

    human readable string to describe what the command is doing

  • :chdir (String)

    directory to change to

Returns:

  • (IO)

    stdout



48
49
50
51
# File 'lib/fpm/fry/exec.rb', line 48

def popen(*args)
  cmd, options, _description = extract_options_and_log(args)
  return IO.popen(cmd, options)
end