From: Ara.T.Howard@... Date: 2005-05-14T03:55:28+09:00 Subject: Re: Get back data from a child (with exec) On Fri, 13 May 2005, Lawrence Oluyede wrote: > Ara.T.Howard@noaa.gov writes: > >> harp:~ > cat a.rb >> IO::popen('-') do |pipe| >> if pipe >> stdout = pipe.read >> puts "parent got <#{ stdout }> from child" >> else >> exec 'echo', '-n', '42' >> end >> end >> >> harp:~ > ruby a.rb >> parent got <42> from child > > Works, but there's a problem. If I open the pipe in read/write mode and exec > a program that reads from stdin it doesn't work :( harp:~ > cat a.rb IO::popen('-', 'r+') do |pipe| if pipe pipe.puts '42' pipe.close_write stdout = pipe.read.strip #pipe.close puts "parent got <#{ stdout }> from child" else exec 'cat' end end harp:~ > ruby a.rb parent got <42> from child you aren't trying to run a program that requires a tty (like top) are you? -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | renunciation is not getting rid of the things of this world, but accepting | that they pass away. --aitken roshi ===============================================================================