From: ara.t.howard@... Date: 2006-11-29T23:52:40+09:00 Subject: Re: I'm a process-spawning idiot. On Wed, 29 Nov 2006, Devin Mullins wrote: > For reference's sake, I don't need fork. The same trick works with > Kernel#system. Some ugly code: > inp, out = IO.pipe > # start Thread.critical > old_stdout = STDOUT.dup > STDOUT.reopen out > system 'echo', 'matz is nice!' > STDOUT.reopen old_stdout > # end Thread.critical > out.close > puts "Hey guess what: #{inp.read}" > __END__ this is an insanely bad idea: a cross platform way to hang you system. try this: harp:~ > cat a.rb big = 42.chr * 4242 inp, out = IO.pipe old_stdout = STDOUT.dup STDOUT.reopen out system 'echo', big STDOUT.reopen old_stdout harp:~ > ruby a.rb # hung process you can't keep writing to a pipe __unless__ someone is guarunteed to be reading from the other end! make it easy on yourself: harp:~ > cat a.rb require 'rubygems' require 'systemu' # gem install systemu systemu ['echo', 'matz is nice!'], :stdout=>STDOUT systemu ['echo', 'matz is nice!'], :stdout=>stdout='' p stdout systemu 'cat', :stdin=>['line1', 'line2'], :stdout=>stdout p stdout harp:~ > ruby a.rb matz is nice! "matz is nice!\n" "matz is nice!\nline1line2" kind regards -a -- if you want others to be happy, practice compassion. if you want to be happy, practice compassion. -- the dalai lama