lib/childprocess/windows/process_builder.rb in childprocess-0.3.9 vs lib/childprocess/windows/process_builder.rb in childprocess-0.4.0

- old
+ new

@@ -1,15 +1,14 @@ module ChildProcess module Windows class ProcessBuilder - attr_accessor :inherit, :detach, :duplex, :environment, :stdout, :stderr, :cwd + attr_accessor :detach, :duplex, :environment, :stdout, :stderr, :cwd attr_reader :stdin def initialize(args) @args = args - @inherit = false @detach = false @duplex = false @environment = nil @cwd = nil @@ -74,11 +73,11 @@ ok = Lib.create_process( nil, # application name @cmd_ptr, # command line nil, # process attributes nil, # thread attributes - @inherit, # inherit handles + true, # inherit handles @flags, # creation flags @env_ptr, # environment @cwd_ptr, # current directory startup_info, # startup info process_info # process info @@ -100,43 +99,38 @@ def setup_detach @flags |= DETACHED_PROCESS if @detach end def setup_io - if @stdout || @stderr - startup_info[:dwFlags] ||= 0 - startup_info[:dwFlags] |= STARTF_USESTDHANDLES + startup_info[:dwFlags] ||= 0 + startup_info[:dwFlags] |= STARTF_USESTDHANDLES - @inherit = true + if @stdout + startup_info[:hStdOutput] = std_stream_handle_for(@stdout) + end - if @stdout - startup_info[:hStdOutput] = std_stream_handle_for(@stdout) - end - - if @stderr - startup_info[:hStdError] = std_stream_handle_for(@stderr) - end + if @stderr + startup_info[:hStdError] = std_stream_handle_for(@stderr) end - setup_stdin if @duplex - end + if @duplex + read_pipe_ptr = FFI::MemoryPointer.new(:pointer) + write_pipe_ptr = FFI::MemoryPointer.new(:pointer) + sa = SecurityAttributes.new(:inherit => true) - def setup_stdin - read_pipe_ptr = FFI::MemoryPointer.new(:pointer) - write_pipe_ptr = FFI::MemoryPointer.new(:pointer) - sa = SecurityAttributes.new(:inherit => true) + ok = Lib.create_pipe(read_pipe_ptr, write_pipe_ptr, sa, 0) + Lib.check_error ok - ok = Lib.create_pipe(read_pipe_ptr, write_pipe_ptr, sa, 0) - Lib.check_error ok + @read_pipe = read_pipe_ptr.read_pointer + @write_pipe = write_pipe_ptr.read_pointer - @read_pipe = read_pipe_ptr.read_pointer - @write_pipe = write_pipe_ptr.read_pointer + Lib.set_handle_inheritance @read_pipe, true + Lib.set_handle_inheritance @write_pipe, false - @inherit = true - Lib.set_handle_inheritance @read_pipe, true - Lib.set_handle_inheritance @write_pipe, false - - startup_info[:hStdInput] = @read_pipe + startup_info[:hStdInput] = @read_pipe + else + startup_info[:hStdInput] = std_stream_handle_for(STDIN) + end end def std_stream_handle_for(io) handle = Lib.handle_for(io)