Help! redirecting stderr 1.6.x and 1.8 differences

Ask a Question related to Ruby, Design and Development.

  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. Similar Questions and Discussions

    1. closing stderr
      I would like to prevent some output that is going to stderr during a call to a third party lib just during that call. My first guess was: ...
    2. reading STDERR
      I have this command that reads logfiles.However, if the command isn't successful it gives me a standard error. my @logData= `program1 -log $data1...
    3. STDERR Weirdness
      I have a Sun E-450 running Solaris 8. I keep getting the STDERR (standard error) messages printed out to the console monitor. I cannont understand...
    4. redirecting stdout/stderr on execl
      consider the following code: ofstream logFile("out.txt"); streambuf *outbuf = cout.rdbuf(logFile.rdbuf()); streambuf *errbuf =...
    5. [How do I:] get what's in $stderr as a string?
      How do I get access to what's in $stderr in the form of a string? In particular, I am using the following code require 'shell'...
  3. #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

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

Posting Permissions

  • You may not post new threads
  • You may 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