IO.popen(), Timeout, broken pipe

Discussion in 'Ruby' started by Florian Weingarten, Dec 17, 2009.

  1. Hey everybody,

    I am having some weird problems with the Timeout module and IO.popen.

    Basically, what I want to do is: Sign some data by gpg. For some reason, gpg
    hangs sometimes and I want to have a timeout. If gpg does not return after
    some time, I want to abort.

    My code looks like this:

    def pgpsign(msg)

    signed_msg = msg

    begin
    Timeout::timeout(@gpgtimeout) {
    io = IO.popen("#{@gpg} --clearsign --home=#{@gpghome}","w+") or return msg
    io.puts msg
    io.close_write
    signed_msg = io.readlines.to_s
    io.close
    }
    rescue
    puts "GPG timed out. Sending unsigned message."
    end

    return signed_msg

    end

    However, if gpg really times out, I will get the following messages

    fo/usr/lib/ruby/1.8/timeout.rb:60:in `puts': execution expired (Timeout::Error)
    from /home/flo/bin/test.rb:423:in `pgpsign'
    from /home/flo/bin/test.rb:421:in `pgpsign'
    from /home/flo/bin/test.rb:410:in `msg'
    from /home/flo/bin/test.rb:578
    from /home/flo/bin/test.rb:574:in `each'
    from /home/flo/bin/test.rb:574
    gpg: [stdout]: write error: Broken pipe
    gpg: iobuf_flush failed on close: file write error

    What's up with that? Any ideas? Why do I get an exception, if I use
    begin/rescue and why does gpg say broken pipe? Is there any easier
    way to do what I want? I am sorry if this is a bit off-topic,
    I know it feels more like a general misunderstanding of pipes than
    a ruby specific problem.

    Thanks in advance,
    Flo
     
    Florian Weingarten, Dec 17, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lee, wonsun
    Replies:
    1
    Views:
    499
    Jack Klein
    Nov 2, 2004
  2. Tom Brown
    Replies:
    0
    Views:
    479
    Tom Brown
    Sep 22, 2005
  3. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,333
    Brian Candler
    Oct 6, 2004
  4. L.
    Replies:
    1
    Views:
    180
  5. Replies:
    1
    Views:
    241
    Ben Morrow
    Jun 2, 2004
Loading...

Share This Page