class Lrun::Runner
{Lrun} provides essential methods to run program with different options using lrun
binary.
{Lrun::Runner} makes it easier to run many programs with same options.
Example¶ ↑
runner = Lrun::Runner.new(:max_cpu_time=>1, :tmpfs=>[["/tmp", 2**20]], :chdir=>"/tmp") # or: runner = Lrun::Runner.new.where(:max_cpu_time=>1, :tmpfs=>[["/tmp", 2**20]], :chdir=>"/tmp") # or: runner = Lrun::Runner.new.max_cpu_time(1).tmpfs('/tmp' => 2**20).chdir('/tmp') runner.options # => {:max_cpu_time=>1, :tmpfs=>[["/tmp", 1048576]], :chdir=>"/tmp"} runner.max_cpu_time(nil).options # => {:tmpfs=>[["/tmp", 1048576]], :chdir=>"/tmp"} runner.run('pwd').stdout # => "/tmp\n" runner.cmd("touch `seq 1 4`").run('ls').stdout # => "1\n2\n3\n4\n" runner.cmd("echo 'puts ENV[?A]' > a.rb").env('A' => 'Hello').run('ruby a.rb').stdout # => "Hello\n"
Attributes
options[RW]
@!attribute [rw] options
@return [Hash] options used in {#run}
Public Class Methods
new(options = {})
click to toggle source
@param [Hash] options options for the runner
# File lib/lrun/runner.rb, line 56 def initialize(options = {}) @options = options end
Public Instance Methods
run(commands)
click to toggle source
Run commands using current {#options}.
@param [Array<String>, String] commands commands to be executed
@see options @see Lrun.run
# File lib/lrun/runner.rb, line 71 def run(commands) Lrun.run commands, @options end
where(options)
click to toggle source
Create a new runner with new options
@param [Hash] options new options to be merged @return [Lrun::Runner] new runner created with merged options
# File lib/lrun/runner.rb, line 79 def where(options) raise TypeError, 'expect options to be a Hash' unless options.is_a? Hash Lrun::Runner.new(Lrun.merge_options(@options, options)) end