Skip to content

Commit

Permalink
Add popen4 option
Browse files Browse the repository at this point in the history
  • Loading branch information
danlucraft committed Aug 14, 2010
1 parent ee24705 commit b6d9317
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.redcar
31 changes: 20 additions & 11 deletions lib/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ def self.version() VERSION end
@track_history = ENV['SESSION_HISTORY'] || ENV['SESSION_TRACK_HISTORY']
@use_spawn = ENV['SESSION_USE_SPAWN']
@use_open3 = ENV['SESSION_USE_OPEN3']
@use_open4 = ENV['SESSION_USE_OPEN4']
@debug = ENV['SESSION_DEBUG']

class << self
attr :track_history, true
attr :use_spawn, true
attr :use_open3, true
attr :use_open4, true
attr :debug, true
def new(*a, &b)
Sh::new(*a, &b)
Expand Down Expand Up @@ -99,11 +101,13 @@ def default_prog= prog
attr :track_history, true
attr :use_spawn, true
attr :use_open3, true
attr :use_open4, true
attr :debug, true
def init
@track_history = nil
@use_spawn = nil
@use_open3 = nil
@use_open4 = nil
@debug = nil
end
alias [] new
Expand All @@ -127,10 +131,12 @@ def init
attr :errproc, true
attr :use_spawn
attr :use_open3
attr :use_open4
attr :debug, true
alias debug? debug
attr :threads

attr :pid

# instance methods
def initialize(*args)
@opts = hashify(*args)
Expand All @@ -150,14 +156,15 @@ def initialize(*args)
@use_spawn = self.class::use_spawn unless self.class::use_spawn.nil?
@use_spawn = getopt('use_spawn', opts) if hasopt('use_spawn', opts)

if defined? JRUBY_VERSION
@use_open3 = true
else
@use_open3 = nil
@use_open3 = Session::use_open3 unless Session::use_open3.nil?
@use_open3 = self.class::use_open3 unless self.class::use_open3.nil?
@use_open3 = getopt('use_open3', opts) if hasopt('use_open3', opts)
end
@use_open3 = nil
@use_open3 = Session::use_open3 unless Session::use_open3.nil?
@use_open3 = self.class::use_open3 unless self.class::use_open3.nil?
@use_open3 = getopt('use_open3', opts) if hasopt('use_open3', opts)

@use_open4 = nil
@use_open4 = Session::use_open4 unless Session::use_open4.nil?
@use_open4 = self.class::use_open4 unless self.class::use_open4.nil?
@use_open4 = getopt('use_open4', opts) if hasopt('use_open4', opts)

@debug = nil
@debug = Session::debug unless Session::debug.nil?
Expand All @@ -170,15 +177,17 @@ def initialize(*args)
@outproc = nil
@errproc = nil

@stdin, @stdout, @stderr =
if @use_open4
@pid, @stdin, @stdout, @stderr = IO::popen4 @prog
else
if @use_spawn
Spawn::spawn @prog
elsif @use_open3
Open3::popen3 @prog
else
__popen3 @prog
end

end
@threads = []

clear
Expand Down

0 comments on commit b6d9317

Please sign in to comment.