On Thu, 2 Mar 2006, Phrogz wrote:

> I'm writing a Ruby script to run Lua code for TextMate. Using:
> output = `lua #{filename}`
> works when the file prints happily, but when an error occurs (e.g. a
> syntax error in the file) the error message is printed to stderr (I
> think) and 'escapes' my capture.
>
> How/can I catch output to stderr from another system command? (I want
> to use the output later, I just don't want it spat out at that point.)
>
>

   harp:~ > gem install session >/dev/null 2>&1 && echo 'success'
   success


   harp:~ > cat a.rb
   require 'rubygems'
   require 'session'
   sh = Session::new
   command = %Q( ruby -e" STDERR.puts :stderr; STDOUT.puts :stdout  " )
   stdout, stderr = sh.execute command

   require 'yaml'
   y "stdout" => stdout
   y "stderr" => stderr
   y "sh.status" => sh.status


   harp:~ > ruby a.rb
   ---
   stdout: |
     stdout

   ---
   stderr: |
     stderr

   ---
   sh.status: 0


-a

-- 
judge your success by what you had to give up in order to get it.
- h.h. the 14th dali lama