Top Level Namespace

Defined Under Namespace

Modules: CommandLine

Instance Method Summary collapse

Instance Method Details

#command_line(*args, **kwargs) {|stdin| ... } ⇒ Result

Run a command and get back the result.

Examples:

command_line('echo', 'hello')
command_line('command_expecting_input') do |stdin|
  stdin.puts "first input"
  stdin.puts "second input"
end
command_line('some_webserver', env: { PORT: '80' })

Parameters:

  • command (String)

    The command to run.

  • args (Array)

    Any arguments passed to the command. All arguments will be converted to strings using to_s.

  • env: (Hash)

    Pass environment variables to use. The key is the name of the environment variable. The value is the value you want that variable to have.

  • Number (Integer, Float, nil)

    of seconds to wait for the block to terminate. Floats can be used to specify fractional seconds. A value of 0 or nil will execute the block without any timeout.

Yields:

  • (stdin)

    Handle any input on stdin that the command needs.

Yield Parameters:

  • stdin (IO)

Returns:

  • (Result)


35
36
37
# File 'lib/command_line/global.rb', line 35

def command_line(*args, **kwargs, &block)
  CommandLine.command_line(*args, **kwargs, &block)
end

#command_line!(*args, **kwargs, &block) ⇒ Result

Same as CommandLine.command_line except that a failure on exit raises an error.

Examples:

command_line!('echo', 'hello')
command_line!('grep')
# => CommandLine::ExitFailureError (usage: grep ...

Returns:

  • (Result)

Raises:

See Also:



54
55
56
# File 'lib/command_line/global.rb', line 54

def command_line!(*args, **kwargs, &block)
  CommandLine.command_line!(*args, **kwargs, &block)
end