From: Robert La Ferla Date: 2007-04-16T09:30:50+09:00 Subject: Re: executing a system command and stopping it after a specified duration? 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