Set the child's current working directory.
Set this to true if you do not care about when or if the process quits.
Set this to true if you want to write to the process' stdin (process.io.stdin)
Modify the child's environment variables
Create a new process with the given args.
@api private @see ChildProcess.build
# File lib/childprocess/abstract_process.rb, line 34 def initialize(args) unless args.all? { |e| e.kind_of?(String) } raise ArgumentError, "all arguments must be String: #{args.inspect}" end @args = args @started = false @exit_code = nil @io = nil @cwd = nil @detach = false @duplex = false @environment = {} end
Is this process running?
@return [Boolean]
# File lib/childprocess/abstract_process.rb, line 114 def alive? started? && !exited? end
Returns true if the process has exited and the exit code was not 0.
@return [Boolean]
# File lib/childprocess/abstract_process.rb, line 124 def crashed? exited? && @exit_code != 0 end
Did the process exit?
@return [Boolean]
# File lib/childprocess/abstract_process.rb, line 104 def exited? raise SubclassResponsibility, "exited?" end
Returns a ChildProcess::AbstractIO subclass to configure the child's IO streams.
# File lib/childprocess/abstract_process.rb, line 53 def io raise SubclassResponsibility, "io" end
@return [Fixnum] the pid of the process after it has started
# File lib/childprocess/abstract_process.rb, line 61 def pid raise SubclassResponsibility, "pid" end
Wait for the process to exit, raising a ChildProcess::TimeoutError if the timeout expires.
# File lib/childprocess/abstract_process.rb, line 133 def poll_for_exit(timeout) log "polling #{timeout} seconds for exit" end_time = Time.now + timeout until (ok = exited?) || Time.now > end_time sleep POLL_INTERVAL end unless ok raise TimeoutError, "process still alive after #{timeout} seconds" end end
Launch the child process
@return [AbstractProcess] self
# File lib/childprocess/abstract_process.rb, line 71 def start launch_process @started = true self end
Forcibly terminate the process, using increasingly harsher methods if possible.
@param [Fixnum] timeout (3) Seconds to wait before trying the next method.
# File lib/childprocess/abstract_process.rb, line 84 def stop(timeout = 3) raise SubclassResponsibility, "stop" end
Block until the process has been terminated.
@return [Fixnum] The exit status of the process
# File lib/childprocess/abstract_process.rb, line 94 def wait raise SubclassResponsibility, "wait" end
# File lib/childprocess/abstract_process.rb, line 168 def assert_started raise Error, "process not started" unless started? end
# File lib/childprocess/abstract_process.rb, line 156 def detach? @detach end
# File lib/childprocess/abstract_process.rb, line 160 def duplex? @duplex end
# File lib/childprocess/abstract_process.rb, line 148 def launch_process raise SubclassResponsibility, "launch_process" end
# File lib/childprocess/abstract_process.rb, line 164 def log(*args) $stderr.puts "#{self.inspect} : #{args.inspect}" if $DEBUG end
# File lib/childprocess/abstract_process.rb, line 152 def started? @started end