Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Uh oh. In a corner. Need help.

Reply
Thread Tools

Uh oh. In a corner. Need help.

 
 
Eric Armstrong
Guest
Posts: n/a
 
      07-18-2006
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.

 
Reply With Quote
 
 
 
 
gwtmp01@mac.com
Guest
Posts: n/a
 
      07-18-2006

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.


 
Reply With Quote
 
 
 
 
Alex Young
Guest
Posts: n/a
 
      07-18-2006
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

 
Reply With Quote
 
Eric Armstrong
Guest
Posts: n/a
 
      07-18-2006
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.
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to "shred" hardive..need software. Xeno Chauvin Computer Support 4 03-13-2005 01:26 PM
Need help with need to Force Garbage Collect John Java 1 08-19-2004 03:32 PM
Need help! I need to add lead zeros to a textbox Teep ASP .Net 2 06-21-2004 01:04 PM
Please help!!! Need datagrid selection to fill textboxes...Need quick!! TN Bella ASP .Net 1 06-18-2004 01:31 AM
Need to compare Photos to DVD software - Need Help? Bob Digital Photography 4 02-04-2004 02:13 AM



Advertisments
 



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