Catching error message


(Tobi Reif) #1

Hi,

Im doing

open(‘error_log.txt’,‘w’) do |file|
file.write domcount foo.xhtml
end

; error_log.txt is then

“Errors occured, no output available”.

, and all the errors are printed to the console. How to write the errors
to the file?

Tobi

···


http://www.pinkjuice.com/

Today, I received a Klez virus from inet@microsoft.com.


(Nobuyoshi Nakada) #2

Hi,

open(‘error_log.txt’,‘w’) do |file|
file.write domcount foo.xhtml
end

; error_log.txt is then

“Errors occured, no output available”.

, and all the errors are printed to the console. How to write the
errors to the file?

def redirect2(output, error, *commands)
if output
saved_out = STDOUT.dup
STDOUT.reopen(output)
end
if error
saved_err = STDOUT.dup
STDERR.reopen(error)
end
system *commands
ensure
STDERR.reopen(saved_err) if error
STDOUT.reopen(saved_out) if output
end

open(‘error_log.txt’,‘w’) do |file|
redirect2(file, file, “domcount”, “foo.xhtml”)
end

···

At Wed, 12 Jun 2002 07:19:49 +0900, Tobias Reif wrote:


Nobu Nakada