Class: Rubysh::Subprocess

Inherits:
Object
  • Object
show all
Defined in:
lib/rubysh/subprocess.rb,
lib/rubysh/subprocess/parallel_io.rb,
lib/rubysh/subprocess/pipe_wrapper.rb,
lib/rubysh/subprocess/pid_aware_parallel_io.rb

Defined Under Namespace

Classes: ParallelIO, PidAwareParallelIO, PipeWrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, blk = nil, directives = [], post_fork = [], runner = nil) ⇒ Subprocess

TODO: switch directives over to an OrderedHash of some form? Really want to preserve the semantics here.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rubysh/subprocess.rb', line 17

def initialize(args, blk=nil, directives=[], post_fork=[], runner=nil)
  raise ArgumentError.new("Must provide an array (#{args.inspect} provided)") unless args.kind_of?(Array)

  if args.length > 0 && blk
    raise ArgumentError.new("Provided both arguments (#{args.inspect}) and a block (#{blk.inspect}). You can only provide one.")
  elsif args.length == 0 && !blk
    raise ArgumentError.new("No command specified (#{args.inspect} provided)")
  end

  @command = args[0]
  @args = args[1..-1]
  @blk = blk
  @directives = directives
  @runner = runner

  Rubysh.assert(@directives.length == 0 || @runner, "Directives provided but no runner is", true)

  @exec_status = nil
  @post_fork = post_fork

  @pid = nil
  @status = nil
  @exec_error = nil

  Rubysh.log.debug("Just created: #{self}")
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



12
13
14
# File 'lib/rubysh/subprocess.rb', line 12

def args
  @args
end

#commandObject

Returns the value of attribute command.



12
13
14
# File 'lib/rubysh/subprocess.rb', line 12

def command
  @command
end

#directivesObject

Returns the value of attribute directives.



12
13
14
# File 'lib/rubysh/subprocess.rb', line 12

def directives
  @directives
end

#exec_errorObject

Returns the value of attribute exec_error.



13
14
15
# File 'lib/rubysh/subprocess.rb', line 13

def exec_error
  @exec_error
end

#pidObject

Returns the value of attribute pid.



13
14
15
# File 'lib/rubysh/subprocess.rb', line 13

def pid
  @pid
end

#runnerObject

Returns the value of attribute runner.



12
13
14
# File 'lib/rubysh/subprocess.rb', line 12

def runner
  @runner
end

#statusObject

Returns the value of attribute status.



13
14
15
# File 'lib/rubysh/subprocess.rb', line 13

def status
  @status
end

Instance Method Details

#runObject



48
49
50
51
# File 'lib/rubysh/subprocess.rb', line 48

def run
  do_run unless @pid
  @pid
end

#to_sObject



44
45
46
# File 'lib/rubysh/subprocess.rb', line 44

def to_s
  "Subprocess: command=#{@command.inspect} blk=#{@blk.inspect} args=#{@args.inspect} directives: #{@directives.inspect}"
end

#wait(nonblock = false) ⇒ Object



53
54
55
56
# File 'lib/rubysh/subprocess.rb', line 53

def wait(nonblock=false)
  do_wait(nonblock) unless @status
  @status
end