From 6d67d9c2af57233743187a92b7e651174d6eb42b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 26 Aug 2013 00:35:03 +0000 Subject: process (qx): disambiguate err/err_str, add no_raise I forgot :err is already handled by Process.spawn, so split out the functionality into err_str where we want to use it. Also, add a :no_raise flag which will allow us to better handle avprobe/soxi calls which can fail and avoid needless exceptions. --- lib/dtas/process.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/dtas/process.rb') diff --git a/lib/dtas/process.rb b/lib/dtas/process.rb index c19b5c5..2cf59c7 100644 --- a/lib/dtas/process.rb +++ b/lib/dtas/process.rb @@ -46,7 +46,8 @@ module DTAS::Process # :nodoc: r, w = IO.pipe opts = opts.merge(out: w) r.binmode - if err = opts[:err] + no_raise = opts.delete(:no_raise) + if err_str = opts.delete(:err_str) re, we = IO.pipe re.binmode opts[:err] = we @@ -57,16 +58,15 @@ module DTAS::Process # :nodoc: retry end w.close - if err + if err_str we.close res = "" - want = { r => res, re => err } + want = { r => res, re => err_str } begin readable = IO.select(want.keys) or next readable[0].each do |io| - bytes = io.nread begin - want[io] << io.read_nonblock(bytes > 0 ? bytes : 11) + want[io] << io.read_nonblock(2000) rescue Errno::EAGAIN # spurious wakeup, bytes may be zero rescue EOFError @@ -76,12 +76,14 @@ module DTAS::Process # :nodoc: end until want.empty? re.close else - res = r.read + res = r.read # read until EOF end r.close _, status = Process.waitpid2(pid) return res if status.success? - raise RuntimeError, "`#{Shellwords.join(cmd)}' failed: #{status.inspect}" + return status if no_raise + raise RuntimeError, + "`#{Shellwords.join(Array(cmd))}' failed: #{status.inspect}" end # XXX only for DTAS::Source::{Sox,Av}.try -- cgit v1.2.3-24-ge0c7