Uh oh. In a corner. Need help.

Discussion in 'Ruby' started by Eric Armstrong, Jul 18, 2006.

  1. My rakefile needs to abort when an html
    file can't be parsed into REXML, so I
    can report the error and fix it. But...

    Running tidy in a subshell, I can find
    no way to access the error message it
    sends to std error. I can see it, but
    is there a way to get ruby to see it?

    This idiom doesn't seem to work

    sh "tidy ... > file" do |ok, res|
    if !ok then
    # Never runs
    end
    end

    The "result" is an empty string. Std out
    goes to the file, as expected, but std
    error does not go to res.

    Trying to run htree instead, I have some
    strange ".so not found" error that I
    posted last week, but am unable to decipher
    on my own. (Of necessity, ruby is in a
    non-standard location, and that seems to be
    causing difficulties.)

    I need a workaround, or a different strategy.
    Eric Armstrong, Jul 18, 2006
    #1
    1. Advertising

  2. Eric Armstrong

    Guest

    On Jul 17, 2006, at 11:39 PM, Eric Armstrong wrote:
    > Running tidy in a subshell, I can find
    > no way to access the error message it
    > sends to std error. I can see it, but
    > is there a way to get ruby to see it?
    >
    > This idiom doesn't seem to work
    >
    > sh "tidy ... > file" do |ok, res|
    > if !ok then
    > # Never runs
    > end
    > end


    You can redirect stderr to a file:

    tidy ... > file 2> errlog

    Maybe that will get you going in the right direction.
    , Jul 18, 2006
    #2
    1. Advertising

  3. Eric Armstrong

    Alex Young Guest

    Eric Armstrong wrote:
    > My rakefile needs to abort when an html
    > file can't be parsed into REXML, so I
    > can report the error and fix it. But...
    >
    > Running tidy in a subshell, I can find
    > no way to access the error message it
    > sends to std error. I can see it, but
    > is there a way to get ruby to see it?

    You can:

    - Use open3, which gives you access to stderr.
    (http://ruby-doc.org/stdlib/libdoc/open3/rdoc/index.html)

    - Use ruby-tidy, which wraps the tidy library and gives you exceptions
    when things go wrong. (http://rubyforge.org/projects/tidy)

    - Redirect stderr in your shell command. ("tidy ... > file 2> errors")

    I've used the second method quite successfully. It's dead simple, but
    you've got to be careful about different Ruby threads using the library.
    It's quite easy to make it go pop unless you wrap it in a critical
    section.

    --
    Alex
    Alex Young, Jul 18, 2006
    #3
  4. Thanks, Alex. And you, too, "gwtmp01".
    Cripes. I never knew about "2>"! That's
    the easiest solution, in this case.

    I appreciate the additional information,
    as well. They give me some alternatives
    to examine.

    You guys saved the day! Thanks much.

    Alex Young wrote:
    > Eric Armstrong wrote:
    >> My rakefile needs to abort when an html
    >> file can't be parsed into REXML, so I
    >> can report the error and fix it. But...
    >>
    >> Running tidy in a subshell, I can find
    >> no way to access the error message it
    >> sends to std error. I can see it, but
    >> is there a way to get ruby to see it?

    > You can:
    >
    > - Use open3, which gives you access to stderr.
    > (http://ruby-doc.org/stdlib/libdoc/open3/rdoc/index.html)
    >
    > - Use ruby-tidy, which wraps the tidy library and gives you exceptions
    > when things go wrong. (http://rubyforge.org/projects/tidy)
    >
    > - Redirect stderr in your shell command. ("tidy ... > file 2> errors")
    >
    > I've used the second method quite successfully. It's dead simple, but
    > you've got to be careful about different Ruby threads using the library.
    > It's quite easy to make it go pop unless you wrap it in a critical
    > section.
    >
    Eric Armstrong, Jul 18, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. csgraham74
    Replies:
    2
    Views:
    407
    csgraham74
    Aug 11, 2005
  2. Xah Lee
    Replies:
    9
    Views:
    354
    John Bokma
    Jul 19, 2005
  3. Xah Lee
    Replies:
    0
    Views:
    352
    Xah Lee
    Nov 24, 2005
  4. Xah Lee
    Replies:
    80
    Views:
    1,647
    Claudio Grondi
    Feb 16, 2006
  5. Dave Rose
    Replies:
    2
    Views:
    126
    Dave Rose
    Apr 19, 2007
Loading...

Share This Page