On Sat, 7 Oct 2006, OliverMarchand wrote: > ara.t.howard / noaa.gov schrieb: >> your analysis is correct, it's why i wrote open4. however, you cannot wait on >> the program with 'getstatusoutput' either - at least i don't see the child pid >> in there? >> >> do you mean you just need the exit_status? i assume so given the interface >> above. > > Thanks for your quick answer. > > I was assuming that my getstatusoutput returns after the process has > finished. I was wanting to add a timeout parameter and an exception for > overly long executions, but left that discussion out of the original post to > make it as simple as possible. > > Thanks for hinting open4, the only thing I am wondering is the best method > to wait for pid to finish!? Now I can write some "while pid exists do > nothing", but doen't that consume unnecessary cyles? using open4? it's already written for you: harp:~ > cat a.rb require 'open4' include Open4 stdin, stdout, stderr = 'foobar', '', '' status = spawn 'cat', :stdin=>stdin, :stdout=>stdout, :stderr=>stderr, :timeout=>4 puts stdout stdin, stdout, stderr = 'foobar', '', '' status = spawn 'sleep 10 && cat', :stdin=>stdin, :stdout=>stdout, :stderr=>stderr, :timeout=>4 puts stdout harp:~ > ruby a.rb foobar /home/ahoward//lib/ruby/1.8/timeout.rb:43:in `pop': execution expired (Timeout::Error) from /home/ahoward//lib/ruby/site_ruby/1.8/open4.rb:151:in `all_done' from /home/ahoward//lib/ruby/site_ruby/1.8/open4.rb:151:in `all_done' from /home/ahoward//lib/ruby/site_ruby/1.8/open4.rb:144:in `run' from /home/ahoward//lib/ruby/site_ruby/1.8/open4.rb:295:in `spawn' from /home/ahoward//lib/ruby/site_ruby/1.8/open4.rb:65:in `popen4' from /home/ahoward//lib/ruby/site_ruby/1.8/open4.rb:273:in `spawn' from /home/ahoward//lib/ruby/1.8/timeout.rb:45:in `timeout' from /home/ahoward//lib/ruby/site_ruby/1.8/open4.rb:272:in `spawn' from a.rb:8 if you really don't want to install it at least steal the code - it's criminal to re-write stuff like this! ;-) -a -- in order to be effective truth must penetrate like an arrow - and that is likely to hurt. -- wei wu wei