class RComp::Process
Public Class Methods
new(cmd, timeout, out, err)
click to toggle source
Initialize a new process
cmd - An array of shellwords of a command timeout - Time until the process is automatically killed out - Path
to send stdout of process err - Path
to send stderr of process
# File lib/rcomp/process.rb, line 14 def initialize(cmd, timeout, out, err) @timeout = timeout @process = ChildProcess.build(*cmd) @process.io.stdout = File.new(out, 'w') @process.io.stderr = File.new(err, 'w') end
Public Instance Methods
run()
click to toggle source
Runs a process and with a specified command and timeout
Returns nothing
# File lib/rcomp/process.rb, line 24 def run begin @process.start rescue ChildProcess::LaunchError => e raise StandardError.new(e.message) end begin @process.poll_for_exit(@timeout) rescue ChildProcess::TimeoutError @timedout = true @process.stop(@timeout) end end
timedout?()
click to toggle source
Check if the proccess timed out or not
Returns a boolean
# File lib/rcomp/process.rb, line 42 def timedout? @timedout ||= false end