Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: open3.rb
#
[0] Fix | Delete
# = open3.rb: Popen, but with stderr, too
[1] Fix | Delete
#
[2] Fix | Delete
# Author:: Yukihiro Matsumoto
[3] Fix | Delete
# Documentation:: Konrad Meyer
[4] Fix | Delete
#
[5] Fix | Delete
# Open3 gives you access to stdin, stdout, and stderr when running other
[6] Fix | Delete
# programs.
[7] Fix | Delete
#
[8] Fix | Delete
[9] Fix | Delete
#
[10] Fix | Delete
# Open3 grants you access to stdin, stdout, and stderr when running another
[11] Fix | Delete
# program. Example:
[12] Fix | Delete
#
[13] Fix | Delete
# require "open3"
[14] Fix | Delete
# include Open3
[15] Fix | Delete
#
[16] Fix | Delete
# stdin, stdout, stderr = popen3('nroff -man')
[17] Fix | Delete
#
[18] Fix | Delete
# Open3.popen3 can also take a block which will receive stdin, stdout and
[19] Fix | Delete
# stderr as parameters. This ensures stdin, stdout and stderr are closed
[20] Fix | Delete
# once the block exits. Example:
[21] Fix | Delete
#
[22] Fix | Delete
# require "open3"
[23] Fix | Delete
#
[24] Fix | Delete
# Open3.popen3('nroff -man') { |stdin, stdout, stderr| ... }
[25] Fix | Delete
#
[26] Fix | Delete
[27] Fix | Delete
module Open3
[28] Fix | Delete
#
[29] Fix | Delete
# Open stdin, stdout, and stderr streams and start external executable.
[30] Fix | Delete
# Non-block form:
[31] Fix | Delete
#
[32] Fix | Delete
# require 'open3'
[33] Fix | Delete
#
[34] Fix | Delete
# stdin, stdout, stderr = Open3.popen3(cmd)
[35] Fix | Delete
#
[36] Fix | Delete
# Block form:
[37] Fix | Delete
#
[38] Fix | Delete
# require 'open3'
[39] Fix | Delete
#
[40] Fix | Delete
# Open3.popen3(cmd) { |stdin, stdout, stderr| ... }
[41] Fix | Delete
#
[42] Fix | Delete
# The parameter +cmd+ is passed directly to Kernel#exec.
[43] Fix | Delete
#
[44] Fix | Delete
# _popen3_ is like _system_ in that you can pass extra parameters, and the
[45] Fix | Delete
# strings won't be mangled by shell expansion.
[46] Fix | Delete
#
[47] Fix | Delete
# stdin, stdout, stderr = Open3.popen3('identify', '/weird path/with spaces/and "strange" characters.jpg')
[48] Fix | Delete
# result = stdout.read
[49] Fix | Delete
#
[50] Fix | Delete
def popen3(*cmd)
[51] Fix | Delete
pw = IO::pipe # pipe[0] for read, pipe[1] for write
[52] Fix | Delete
pr = IO::pipe
[53] Fix | Delete
pe = IO::pipe
[54] Fix | Delete
[55] Fix | Delete
pid = fork{
[56] Fix | Delete
# child
[57] Fix | Delete
fork{
[58] Fix | Delete
# grandchild
[59] Fix | Delete
pw[1].close
[60] Fix | Delete
STDIN.reopen(pw[0])
[61] Fix | Delete
pw[0].close
[62] Fix | Delete
[63] Fix | Delete
pr[0].close
[64] Fix | Delete
STDOUT.reopen(pr[1])
[65] Fix | Delete
pr[1].close
[66] Fix | Delete
[67] Fix | Delete
pe[0].close
[68] Fix | Delete
STDERR.reopen(pe[1])
[69] Fix | Delete
pe[1].close
[70] Fix | Delete
[71] Fix | Delete
exec(*cmd)
[72] Fix | Delete
}
[73] Fix | Delete
exit!(0)
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
pw[0].close
[77] Fix | Delete
pr[1].close
[78] Fix | Delete
pe[1].close
[79] Fix | Delete
Process.waitpid(pid)
[80] Fix | Delete
pi = [pw[1], pr[0], pe[0]]
[81] Fix | Delete
pw[1].sync = true
[82] Fix | Delete
if defined? yield
[83] Fix | Delete
begin
[84] Fix | Delete
return yield(*pi)
[85] Fix | Delete
ensure
[86] Fix | Delete
pi.each{|p| p.close unless p.closed?}
[87] Fix | Delete
end
[88] Fix | Delete
end
[89] Fix | Delete
pi
[90] Fix | Delete
end
[91] Fix | Delete
module_function :popen3
[92] Fix | Delete
end
[93] Fix | Delete
[94] Fix | Delete
if $0 == __FILE__
[95] Fix | Delete
a = Open3.popen3("nroff -man")
[96] Fix | Delete
Thread.start do
[97] Fix | Delete
while line = gets
[98] Fix | Delete
a[0].print line
[99] Fix | Delete
end
[100] Fix | Delete
a[0].close
[101] Fix | Delete
end
[102] Fix | Delete
while line = a[1].gets
[103] Fix | Delete
print ":", line
[104] Fix | Delete
end
[105] Fix | Delete
end
[106] Fix | Delete
[107] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function