Without STDERR.
, puts
write the output to the stdout. stdout in the child process is pipe. Anything written to the stdout is not printed, but sent to the pipe.
The child process write 2 lines.
Dad say: Get a job!
OK
The parent process read a line (Dad say: Get a job!), and print that.
Child says: Dad say: Get a job!
^^^^^^^^^^^^^^^^^^^ -- read from the pipe (stdout of child process).
If you also want print OK
, call pipe.gets
twice or use pipe.read
to read all output of children:
pipe = IO.popen("-","w+")
if pipe
pipe.puts "Get a job!"
puts "Child says: #{pipe.read}"
else
puts "Dad says: #{gets.chomp}"
puts "OK"
end