Guest User

Untitled

a guest
Apr 26th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. require ENV['TM_SUPPORT_PATH'] + '/lib/io'
  2. require 'fcntl'
  3.  
  4. module TextMate
  5. module Process
  6. class << self
  7.  
  8. TM_INTERACTIVE_INPUT_DYLIB = ENV['TM_SUPPORT_PATH'] + '/lib/tm_interactive_input.dylib'
  9.  
  10. def async(exec, options = {}, &block)
  11.  
  12. pr = ::IO::pipe
  13. pe = ::IO::pipe
  14.  
  15. pid = fork{
  16.  
  17. pr[0].close
  18. STDOUT.reopen(pr[1])
  19. pr[1].close
  20.  
  21. pe[0].close
  22. STDERR.reopen(pe[1])
  23. pe[1].close
  24.  
  25. if File.exists? TM_INTERACTIVE_INPUT_DYLIB
  26. dil = ENV['DYLD_INSERT_LIBRARIES']
  27. if dil.nil? or dil.empty?
  28. ENV['DYLD_INSERT_LIBRARIES'] = TM_INTERACTIVE_INPUT_DYLIB
  29. elsif dil !~ /#{TM_INTERACTIVE_INPUT_DYLIB}/
  30. ENV['DYLD_INSERT_LIBRARIES'] = "#{TM_INTERACTIVE_INPUT_DYLIB}:#{dil}"
  31. end
  32.  
  33. ENV['DYLD_FORCE_FLAT_NAMESPACE'] = "1"
  34. ENV['TM_INTERACTIVE_INPUT'] = "AUTO" + ((options.has_key? :echo) ? "|ECHO" : "")
  35. end
  36.  
  37. exec(*exec)
  38. }
  39.  
  40. pr[1].close
  41. pe[1].close
  42.  
  43. if block.nil?
  44. return [pr[0], pe[0], pid]
  45. else
  46. TextMate::IO.sync = true if options.has_key? :sync
  47. TextMate::IO.exhaust(:out => pr[0], :err => pe[0]) do |str, type|
  48. block.call(str, type)
  49. end
  50. ::Process.waitpid(pid)
  51. return nil
  52. end
  53.  
  54. end
  55.  
  56. def sync(exec, options = {})
  57. out = ""
  58. err = ""
  59.  
  60. async(exec, options) do |str, fd|
  61. case fd
  62. when :out then out << str
  63. when :err then err << str
  64. end
  65. end
  66.  
  67. [out,err]
  68. end
  69.  
  70. end
  71. end
  72. end
Add Comment
Please, Sign In to add comment