diff --git a/lib/tty/command.rb b/lib/tty/command.rb index ae93d0d..eedaacc 100644 --- a/lib/tty/command.rb +++ b/lib/tty/command.rb @@ -32,6 +32,10 @@ def self.record_separator=(sep) @record_separator = sep end + def self.windows? + !!(RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/) + end + attr_reader :printer # Initialize a Command object diff --git a/lib/tty/command/child_process.rb b/lib/tty/command/child_process.rb index 4f29939..2703312 100644 --- a/lib/tty/command/child_process.rb +++ b/lib/tty/command/child_process.rb @@ -28,9 +28,9 @@ def spawn(cmd) pty = try_loading_pty if pty # Create pipes - in_rd, in_wr = pty ? PTY.open : IO.pipe("utf-8") # reading - out_rd, out_wr = pty ? PTY.open : IO.pipe("utf-8") # writing - err_rd, err_wr = pty ? PTY.open : IO.pipe("utf-8") # error + in_rd, in_wr = pty ? PTY.open : IO.pipe('utf-8') # reading + out_rd, out_wr = pty ? PTY.open : IO.pipe('utf-8') # writing + err_rd, err_wr = pty ? PTY.open : IO.pipe('utf-8') # error in_wr.sync = true if binmode @@ -41,10 +41,19 @@ def spawn(cmd) # redirect fds opts = { - :in => in_rd, in_wr => :close, - :out => out_wr, out_rd => :close, - :err => err_wr, err_rd => :close - }.merge(process_opts) + in: in_rd, + out: out_wr, + err: err_wr + } + unless TTY::Command.windows? + close_child_fds = { + in_wr => :close, + out_rd => :close, + err_rd => :close + } + opts.merge!(close_child_fds) + end + opts.merge!(process_opts) pid = Process.spawn(cmd.to_command, opts)