On Mon, 16 Apr 2007, Robert La Ferla wrote:

>
> On Apr 15, 2007, at 3:39 AM, Stefan Mahlitz wrote:
>
>> 
>> If you want to read from '/dev/video' you could combine james.d.masters
>> and Dan Zwells suggestions - but using system or `
>> 
>> require "timeout"
>> begin
>>  Timeout::timeout(600) do
>>    system("cat /dev/video > test.mpg")
>>    # `cat /dev/video > test.mpg`
>>  end
>> rescue Timeout::Error
>>  puts("Done")
>> end
>> 
>> or
>> 
>> require "timeout"
>> begin
>>  Timeout::timeout(600) do
>>    File.open("/dev/video", "rb") do |input|
>>      File.open("test.mpg", "wb") do |output|
>>        input.each_byte {|byte| output.putc(byte)}
>>      end
>>    end
>>  end
>> rescue Timeout::Error
>>  puts("Done")
>> end
>
> Thanks.
>
> A couple of issues:
>
> 1.  The time out is working but the "cat" process is not terminated.  I tried 
> both system(cmd) and `#{cmd}`.
>
> 2.  I wonder if Ruby is fast enough to read /dev/video and dump it to a file 
> without a delay.  Imagine if this is running for a couple of hours...
>
>
> BTW - My configuration is:
>
> % ruby --version
> ruby 1.8.5 (2007-03-13 patchlevel 35) [i386-linux]
>
> Fedora Linux 2.6.20-1.2933.fc6
>

require 'rubygems'
require 'open4'    ### gem install open4


Open4.spawn 'cat /dev/video', :timeout=>600, :stdout=>buf=''

p buf.size


-a
-- 
be kind whenever possible... it is always possible.
- the dalai lama