Module: Ndo
- Defined in:
- lib/ndo.rb,
lib/ndo/popen.rb
Defined Under Namespace
Classes: Host, MultiHost, Pipe, Process, Result
Class Method Summary collapse
-
.popen(*cmd) ⇒ Object
NOTE: This was using the Open4 gem previously.
Class Method Details
.popen(*cmd) ⇒ Object
NOTE: This was using the Open4 gem previously. That method turned out to not be portable across rubies and operating systems, that’s why we try our luck with maintaining this popen4 here.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ndo/popen.rb', line 26 def popen(*cmd) c_in, c_out, c_err = 3.times.map { Pipe.new(*IO.pipe) } pid = fork do c_in.write.close STDIN.reopen(c_in.read) c_in.read.close c_out.read.close STDOUT.reopen(c_out.write) c_out.write.close c_err.read.close STDERR.reopen(c_err.write) c_err.write.close exec(*cmd) fail "NOT REACHED: EXEC FAILED" end c_in.read.close c_out.write.close c_err.write.close # c_in.sync = true Process.new(pid, c_in.write, c_out.read, c_err.read) end |