Help! redirecting stderr 1.6.x and 1.8 differences

A

Andrew Walrond

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
 
G

Gennady

I would do

$stderr.reopen $stdout

instead of

$stderr = $stdout

Gennady.


----- Original Message -----
From: "Andrew Walrond" <[email protected]>
To: "ruby-talk ML" <[email protected]>
Sent: Tuesday, August 26, 2003 11:19 AM
Subject: Help! redirecting stderr 1.6.x and 1.8 differences
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top