Method: Overcommit::Subprocess.spawn
- Defined in:
- lib/overcommit/subprocess.rb
.spawn(args, options = {}) ⇒ Result
Spawns a new process using the given array of arguments (the first element is the command).
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/overcommit/subprocess.rb', line 29 def spawn(args, = {}) args = win32_prepare_args(args) if OS.windows? process = ChildProcess.build(*args) out, err = assign_output_streams(process) process.duplex = true if [:input] # Make stdin available if needed process.start if [:input] begin process.io.stdin.puts([:input]) rescue StandardError # rubocop:disable Lint/HandleExceptions # Silently ignore if the standard input stream of the spawned # process is closed before we get a chance to write to it. This # happens on JRuby a lot. ensure process.io.stdin.close end end process.wait err.rewind out.rewind Result.new(process.exit_code, out.read, err.read) end |