I want to log stdout and stderr of a compile to a file, so I use (for
example) this simple ruby script, which works under 1.6.8 and doesn't under
1.8

---------------------------------
#!/bin/ruby -w

$stdout.reopen("my.log","w")
$stdout.sync=true
$stderr=$stdout

$stdout.puts("This from stdout")
$stderr.puts("This from stderr")

system("gcc foobar")
---------------------------------

Running with 1.6.8....

rubyx@atlas public $ ruby --version
ruby 1.6.8 (2002-12-24) [i686-linux-gnu]
rubyx@atlas public $ ./testout.rb
rubyx@atlas public $ cat my.log
This from stdout
This from stderr
gcc: foobar: No such file or directory
gcc: no input files
rubyx@atlas public $

And with 1.8.0...

rubyx@atlas public $ ruby --version
ruby 1.8.0 (2003-08-04) [i686-linux]
rubyx@atlas public $ ./testout.rb
gcc: foobar: No such file or directory
gcc: no input files
rubyx@atlas public $ cat my.log
This from stdout
This from stderr
rubyx@atlas public $


So what is the correct way to do this which will work under 1.8 but also
supports 1.6.8?

TIA
Andrew Walrond