On Sat, 7 Oct 2006, OliverMarchand wrote:
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