Method: ReactNativeUtil::Util#execute

Defined in:
lib/react_native_util/util.rb

#execute(*command, chdir: nil, output: STDOUT, log: STDOUT) ⇒ Object

Execute the specified command. If output is non-nil, generate a log at that location. Main log (open) is log.

Parameters:

  • command

    Variadic command to be executed

  • chdir (String, nil) (defaults to: nil)

    Directory in which to execute the command

  • output (String, Symbol, IO) (defaults to: STDOUT)

    Output for command (path, IO or a symbol such as :close)

  • log (IO, nil) (defaults to: STDOUT)

    Open IO for main log (nil to suppress logging command to main log)

Returns:

  • nil

Raises:

  • ExecutionError If the command fails



43
44
45
46
47
48
49
50
51
52
# File 'lib/react_native_util/util.rb', line 43

def execute(*command, chdir: nil, output: STDOUT, log: STDOUT)
  log.log_command command unless log.nil?

  options = chdir.nil? ? {} : { chdir: chdir }
  system(*command, options.merge(%i[err out] => output))

  raise ExecutionError, "#{command.shelljoin}: #{$?}" unless $?.success?

  nil
end