Help! redirecting stderr 1.6.x and 1.8 differences

Discussion in 'Ruby' started by Andrew Walrond, Aug 26, 2003.

  1. 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
     
    Andrew Walrond, Aug 26, 2003
    #1
    1. Advertisements

  2. Andrew Walrond

    Gennady Guest

    I would do

    $stderr.reopen $stdout

    instead of

    $stderr = $stdout

    Gennady.


    ----- Original Message -----
    From: "Andrew Walrond" <>
    To: "ruby-talk ML" <>
    Sent: Tuesday, August 26, 2003 11:19 AM
    Subject: Help! redirecting stderr 1.6.x and 1.8 differences
     
    Gennady, Aug 26, 2003
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.