Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require ENV['TM_SUPPORT_PATH'] + '/lib/io'
- require 'fcntl'
- module TextMate
- module Process
- class << self
- TM_INTERACTIVE_INPUT_DYLIB = ENV['TM_SUPPORT_PATH'] + '/lib/tm_interactive_input.dylib'
- def async(exec, options = {}, &block)
- pr = ::IO::pipe
- pe = ::IO::pipe
- pid = fork{
- pr[0].close
- STDOUT.reopen(pr[1])
- pr[1].close
- pe[0].close
- STDERR.reopen(pe[1])
- pe[1].close
- if File.exists? TM_INTERACTIVE_INPUT_DYLIB
- dil = ENV['DYLD_INSERT_LIBRARIES']
- if dil.nil? or dil.empty?
- ENV['DYLD_INSERT_LIBRARIES'] = TM_INTERACTIVE_INPUT_DYLIB
- elsif dil !~ /#{TM_INTERACTIVE_INPUT_DYLIB}/
- ENV['DYLD_INSERT_LIBRARIES'] = "#{TM_INTERACTIVE_INPUT_DYLIB}:#{dil}"
- end
- ENV['DYLD_FORCE_FLAT_NAMESPACE'] = "1"
- ENV['TM_INTERACTIVE_INPUT'] = "AUTO" + ((options.has_key? :echo) ? "|ECHO" : "")
- end
- exec(*exec)
- }
- pr[1].close
- pe[1].close
- if block.nil?
- return [pr[0], pe[0], pid]
- else
- TextMate::IO.sync = true if options.has_key? :sync
- TextMate::IO.exhaust(:out => pr[0], :err => pe[0]) do |str, type|
- block.call(str, type)
- end
- ::Process.waitpid(pid)
- return nil
- end
- end
- def sync(exec, options = {})
- out = ""
- err = ""
- async(exec, options) do |str, fd|
- case fd
- when :out then out << str
- when :err then err << str
- end
- end
- [out,err]
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment