To redirect stderr to stdout from inside a Ruby script you can use the IO#reopen
method:
# script.rb
$stderr.reopen($stdout)
fail 'error' # Messages from execeptions are usually printed on stderr
If you run the script in the shell, redirecting stderr to /dev/null
, you can see that the exception message is printed on stdout:
$ ruby script.rb 2> /dev/null
foo.rb:2:in `<main>': foo (RuntimeError)
Edit: That said you probably will have to find a more appropriate solution to print error messages on your browser, for example you will need to encode HTML entities in error messages.