Method: Pod::Executable.execute_command

Defined in:
lib/cocoapods/executable.rb

.execute_command(executable, command, raise_on_failure = true) ⇒ String

Executes the given command displaying it if in verbose mode.

Parameters:

  • executable (String)

    The binary to use.

  • command (Array<#to_s>)

    The command to send to the binary.

  • raise_on_failure (Boolean) (defaults to: true)

    Whether it should raise if the command fails.

Returns:

  • (String)

    the output of the command (STDOUT and STDERR).

Raises:

  • If the executable could not be located.

  • If the command fails and the raise_on_failure is set to true.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cocoapods/executable.rb', line 48

def self.execute_command(executable, command, raise_on_failure = true)
  bin = which!(executable)

  command = command.map(&:to_s)
  if File.basename(bin) == 'tar.exe'
    # Tar on Windows needs --force-local
    command.push('--force-local')
  end
  full_command = "#{bin} #{command.join(' ')}"

  if Config.instance.verbose?
    UI.message("$ #{full_command}")
    stdout = Indenter.new(STDOUT)
    stderr = Indenter.new(STDERR)
  else
    stdout = Indenter.new
    stderr = Indenter.new
  end

  status = popen3(bin, command, stdout, stderr)
  stdout = stdout.join
  stderr = stderr.join
  output = stdout + stderr
  unless status.success?
    if raise_on_failure
      raise Informative, "#{full_command}\n\n#{output}"
    else
      UI.message("[!] Failed: #{full_command}".red)
    end
  end

  output
end