# Timeout when reading from a pipe

**URL:** <https://www.ruby-forum.com/t/timeout-when-reading-from-a-pipe/141207>\
**Category:** Ruby\
**Created:** [June 23, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/timeout-when-reading-from-a-pipe/141207 "2008-06-23T16:32:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![melmoth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@melmoth](https://www.ruby-forum.com/u/melmoth)\
**Post date:** [June 23, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/timeout-when-reading-from-a-pipe/141207/1 "2008-06-23T16:32:28Z")

</div>

Hi,  
I would like to launch a process (external executable) and raise an  
exception if I cannot read any output from it on the stdout.  
Is that possible?

Thanks in advance

def execute\_mencoder(command)  
IO.popen(command) do |pipe|  
pipe.each("\r") do |line|  
puts line  
end  
end  
raise MediaFormatException if $?.exitstatus != 0  
end

---

<div class="post-metadata">

**Author:** ![melmoth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@melmoth](https://www.ruby-forum.com/u/melmoth)\
**Post date:** [June 23, 2008, 4:37pm UTC](https://www.ruby-forum.com/t/timeout-when-reading-from-a-pipe/141207/2 "2008-06-23T16:37:33Z")

</div>

On Jun 23, 2008, at 8:30 AM, Me Me wrote:

> ```
> puts line
> 
> ```
> 
> end  
> end  
> raise MediaFormatException if $?.exitstatus != 0  
> end

if you are windows no, otherwise yes.

ri Timeout

if you are on windows you’ll want the systemu gem

gem install systemu

regards.

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![melmoth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@melmoth](https://www.ruby-forum.com/u/melmoth)\
**Post date:** [June 28, 2008, 1:16pm UTC](https://www.ruby-forum.com/t/timeout-when-reading-from-a-pipe/141207/3 "2008-06-28T13:16:46Z")

</div>

Hi, still on the subject I’m trying to understand if under Windows  
I can emit and trap custom signals from two processes.  
It should be something like this:

open("|-", “r”) do |child|  
if child  
child.each("\n") do |line|  
puts line  
# emit signal  
end  
child.close  
else  
exec(“ls”, “-l”)  
# trap signal checking a timeout  
# if signal not received for more than 10 secs close child  
# and go on  
end  
end

Is there a way to implement what specified in the commented lines?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![melmoth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@melmoth](https://www.ruby-forum.com/u/melmoth)\
**Post date:** [June 23, 2008, 5:49pm UTC](https://www.ruby-forum.com/t/timeout-when-reading-from-a-pipe/141207/4 "2008-06-23T17:49:14Z")

</div>

> if you are windows no, otherwise yes.

Ok, we discussed about that but it was in another thread.  
So, it’s not even possible to detect that an external exe launched is  
become  
a zombie process?  
Do I have to resort to threads?  
Thans again
