Module: Kernel

Defined in:
lib/neovim/output.rb,
lib/neovim/tools/copy.rb

Class Method Summary collapse

Class Method Details

.system(*cmd) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/neovim/output.rb', line 8

module_function def system *cmd
  ro, wo = IO.pipe
  re, we = IO.pipe
  child = fork do
    STDIN.close
    ro.close ; STDOUT.reopen wo ; wo.close
    re.close ; STDERR.reopen we ; we.close
    exec *cmd
  end
  wo.close
  we.close
  h = { ro => $stdout, re => $stderr, }
  until h.empty? do
    h.keys.each { |r|
      if r.eof? then
        r.close
        h.delete r
      else
        h[ r].puts r.readline
      end
    }
  end
  Process.waitpid child
  $?.success?
end