Class: RazorRisk::Razor::Control::Razor::Executor
- Inherits:
-
Object
- Object
- RazorRisk::Razor::Control::Razor::Executor
- Includes:
- Pantheios, Core::Diagnostics::Logger, Xqsr3::Quality::ParameterChecking
- Defined in:
- lib/razor_risk/razor/control/razor/executor.rb
Overview
Executes operations on a Razor instance.
Instance Method Summary collapse
-
#execute(command, **opts) ⇒ Object
Executes the provided system command and logs its output.
Instance Method Details
#execute(command, **opts) ⇒ Object
Executes the provided system command and logs its output. The system command will be fed new lines to prevent getting stuck on any ‘pause’ statements. The program will be terminated if this process is interupeted.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/razor_risk/razor/control/razor/executor.rb', line 41 def execute command, **opts check_parameter command, 'command', type: ::String rout,wout = IO.pipe rerr,werr = IO.pipe rin,win = IO.pipe tout = Thread.new do while line = rout.readline do log :informational, "#{command}: #{line}".strip end end terr = Thread.new do while line = rerr.readline do log :warning, "#{command}: #{line}".strip end end tin = Thread.new do while true do win.write "\n" sleep(1) end end opts.merge!({ out: wout, err: werr, in: rin, }) begin pid = Process.spawn( command, opts ) Process.wait pid ensure begin Process.kill('SIGKILL', pid) rescue Errno::ESRCH # Process exited normally end win.close tout.exit terr.exit tin.exit end $?.success? end |