Professional Web Applications Themes

Help! redirecting stderr 1.6.x and 1.8 differences - Ruby

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 ...

  1. #1

    Default Help! redirecting stderr 1.6.x and 1.8 differences

    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 Guest

  2. #2

    Default Re: Help! redirecting stderr 1.6.x and 1.8 differences

    I would do

    $stderr.reopen $stdout

    instead of

    $stderr = $stdout

    Gennady.


    ----- Original Message -----
    From: "Andrew Walrond" <andrew@walrond.org>
    To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
    Sent: Tuesday, August 26, 2003 11:19 AM
    Subject: Help! redirecting stderr 1.6.x and 1.8 differences

    > 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
    >
    >
    >


    Gennady Guest

  3. #3

    Default Re: Help! redirecting stderr 1.6.x and 1.8 differences

    maybe by trying: 2> grep-errors.txt
    where 2 is the stderr
    Unregistered Guest

Similar Threads

  1. closing stderr
    By Michael Garriss in forum Ruby
    Replies: 14
    Last Post: September 19th, 12:22 PM
  2. reading STDERR
    By Trina Espinoza in forum PERL Beginners
    Replies: 1
    Last Post: September 12th, 01:11 AM
  3. STDERR Weirdness
    By Donnie in forum Sun Solaris
    Replies: 2
    Last Post: July 22nd, 12:56 PM
  4. redirecting stdout/stderr on execl
    By shea martin in forum UNIX Programming
    Replies: 3
    Last Post: July 21st, 11:02 PM
  5. [How do I:] get what's in $stderr as a string?
    By Mark Wilson in forum Ruby
    Replies: 3
    Last Post: July 6th, 05:44 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139