Method: Subprocess.check_call

Defined in:
lib/subprocess.rb

.check_call(cmd, opts = {}) {|process| ... } ⇒ ::Process::Status

Note:

If you call this function with ‘:stdout => PIPE` or `:stderr => PIPE`, this function will block indefinitely as soon as the OS’s pipe buffer fills up, as neither file descriptor will be read from. To avoid this, use Subprocess::Process#communicate from a passed block.

Like call, except raise a NonZeroExit if the process did not terminate successfully.

Examples:

Grep a file for a string

Subprocess.check_call(%W{grep -q llama ~/favorite_animals})

Communicate with a child process

Subprocess.check_call(%W{sendmail -t}, :stdin => Subprocess::PIPE) do |p|
  p.communicate <<-EMAIL
From: [email protected]
To: [email protected]
Subject: I am so fluffy.

SO FLUFFY!
http://upload.wikimedia.org/wikipedia/commons/3/3e/Unshorn_alpaca_grazing.jpg
  EMAIL
end

Parameters:

Yields:

Yield Parameters:

Returns:

  • (::Process::Status)

    The exit status of the process

Raises:

  • (NonZeroExit)

    if the process returned a non-zero exit status (i.e., was terminated with an error or was killed by a signal)

See Also:



83
84
85
86
87
# File 'lib/subprocess.rb', line 83

def self.check_call(cmd, opts={}, &blk)
  status = Process.new(cmd, opts, &blk).wait
  raise NonZeroExit.new(cmd, status) unless status.success?
  status
end