From: ahoward@... (ara howard) Date: 2002-08-20T03:08:43+09:00 Subject: Re: How do I dup file descriptors in ruby? (diverting STDERR) i'm not sure why, but modifying the constants STDOUT and STDERR seems to give the 'expected' behavior both with the calling process and withing sub-processes (backquoted sub-shell expressions). i tried all manner of delegation, inheritance, extension - but the following is simple and works like it reads : =============================================================================== #!/usr/bin/env ruby # save everything for restoration IN = STDIN.clone ERR = STDERR.clone OUT = STDOUT.clone # the log file $log = open 'logfile', 'w' # redirect STDOUT to logfile STDOUT.reopen $log # merge STDERR and STDOUT STDERR.reopen STDOUT # output goes to logfile `ls non_existent_file` # output goes to logfile $stderr.puts 'foo' # output goes to logfile $stdout.puts 'bar' # output goes to logfile puts 'end test 0' # unmerge STDERR STDERR.reopen ERR # output goes to stderr `ls non_existent_file` # output goes to stderr $stderr.puts 'foo' # STDOUT still points to logfile... # output goes to logfile $stdout.puts 'bar' # output goes to logfile puts 'end test 1' =============================================================================== i am still very confused as to why asigning to $stdout is so much different that modifying STDOUT - especially when concerning sub-processes... -ara