I have the following code:
Any suggestions on how this can be done?
It’s likely that you run into a deadlock caused by pipe buffer sizes. I
suggest to not read and write the whole content but to do it in chunks.
Also, I’d separate the reading and writing code into two threads.
Untested:
Open3.popen3("/usr/sbin/tcpdump -nettr -") { |in_io, out_io, err_io|
t = Thread.new(in_io) do |out|
while ( buff = $stdin.read( 1024 ) )
out.write(buff)
end
out.close
end
$log = “”
while ( b = out_io.read(1024))
$log << b
end
}
HTH
Kind regards
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.