Skip to content

Commit

Permalink
Change to skip child process close options for Windows platform as cl…
Browse files Browse the repository at this point in the history
…osed by default
  • Loading branch information
piotrmurach committed Nov 11, 2017
1 parent 86fd313 commit 4a7ebe5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/tty/command.rb
Expand Up @@ -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
Expand Down
23 changes: 16 additions & 7 deletions lib/tty/command/child_process.rb
Expand Up @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit 4a7ebe5

Please sign in to comment.