i have to fork a process and read a large amount of stdout; however, the
child buffer gets filled up and everything hangs. how do you read
stdout as stream?
the only way i know how to do this is the following two ways; but both
do not work; how can you get the stdout when the method starts so you
can read stdout as it get written to from the child process?
i have to fork a process and read a large amount of stdout; however, the
child buffer gets filled up and everything hangs. how do you read
stdout as stream?
I am not very sure I understand what you want to do. But of one thing
I am sure:
stdout is to write (OUT)
stdin is to read (IN)
In other words, you cannot read from stdout. stdout.gets will never
give you anything of interest.
i have an autonomous process that writes to stdout (my example is called
child.rb). i want to fork this process and read the stdout of the child
process.
the problem is the process produces too much stdout that is fills up the
buffer. how can you read the stdout before the child process ends?
parent calls child
child write stdout
parent reads the stdout
here is my example to demo what i am trying to do: if you run parent.rb
you will see what i am trying to do.
#######################################
parent.rb
#######################################
require ‘open4’
require ‘./child.rb’
command = ‘child.rb’
#try it as return
pid, stdin, stdout, stderr = Open4::popen4(command)
while !stdout.eof? do
puts stdout.gets
end
###################################
########################
child.rb is
########################
(0…100).each do |i|
puts “helloworld #{i}”
sleep 1
puts “goodbye world #{i}”
sleep 1
end
On Thu, Nov 1, 2012 at 10:06 PM, Matthew P. [email protected]
wrote:
i have to fork a process and read a large amount of stdout; however, the
child buffer gets filled up and everything hangs. how do you read
stdout as stream?
the only way i know how to do this is the following two ways; but both
do not work; how can you get the stdout when the method starts so you
can read stdout as it get written to from the child process?