Output of std RUBY scripts truncated in Output Pane

Started by SFdude, June 17, 2012, 03:00:38 AM

Previous topic - Next topic

SFdude

Hi all,

have a simple Ruby script:
  tax.rb
(user enters a $ Value & script returns new Value + Tax).

a) It works fine in a DOS commd. window:
   -  ruby tax.rb

b) It also works in HE,
BUT.... some strings & values are not shown or "disappear"
from HE's Output Pane,
(either with "Auto-Scroll" ON or OFF, no difference!).

Here are my HE Tool settings to run this Ruby script:

  Title:           RubyDO
  Command:    Ruby
  Arguments:  %MainFilePath%
  .
  .
  Save Before: Current Document
  [X]  Show in Context Menu
  [X]  Capture Output

Here's the tax.rb script:
------------------------
taxrate = 0.175

print "Enter price: "
s = gets

subtotal = s.to_f
tax = subtotal * taxrate

puts "\nTax on $#{subtotal} is $#{tax}, so grand total is $#{subtotal+tax}"

-----------------------

Help appreciated!

SFdude
XP-Pro SP3 32bit
ruby 1.9.3p194
HippoEdit 1.49 latest
Firefox 12


alex

Hi Ray,

welcome on forum. There were some strange problems here that messages were moved/lost (do not know why) but hope now works...

According your problem:
- what is lost? And what does not . Please be more concrete. Which "some strings & values" and what mean "not shown or "disappear"". Better step by step description.
- please retest with 1.50: http://forum.hippoedit.com/beta-version-test/alpha-1-50/ , in any case I am now fixing only in .150.
- I do not know ruby, but from what I see you READ something from console (entering this in output window)?
- If you want me to test this, please provide easy instruction how to install ruby and how to check (do not point to ruby web site).

BR, Alex.
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

SFdude

#2
Thanks Alex for that quick reply!  :)

1) Glad my post (and your answer),
showed up in the Forum, (post had disappeared mysteriously ...).

2)   Don't worry about my question.
I think it's a very Ruby-specific issue,
(I'm new @ Ruby).

Found a way around the problem...

Instead of sending the Ruby script results to HE's Output Pane,
I have HE output the script results to a DOS window,
where the results show up fine.

3)   Will follow your advice
and test later with HE 1.50 Beta.

Questions:
  - Can I install HE 1.50 Beta, "in parallel" (together) with my HE 1.49 ?
  - Will my HE 1.49 Colors and Fonts Settings be kept ?
     (want to keep my HE Settings exactly as they are now,
       in both 1.49 and 1.50...)

Reason:
   I have many  Colors and Fonts Settings
in my current 1.49,
and don't want my install of 1.50 to change my 1.49 Settings.

Thanks Alex!
SFdude


alex

2) yes, forwarding the output to DOS window (probaly this just mean do not catch output) is a workaround. But it is nicer to have it captured by HE :) So, if you describe what exactly lost and how to reproduce this with 1.50, I will check that. By design there should be no differences when using in cmd or in HE (output differences).

3) Yes, you can install 1.50 in parallel to 1.49 and they will share the settings. The only disadvantage is, that cache (tmp) files are recreated if you swtich from version to version.
One more plus for you, that 1.50 support syntax highlighting of Ruby better. In 1.49  there are some problems in highlighting of regular expressions.

Br, Alex
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

SFdude

Hi Alex,

>> If you want me to test this,
>> please provide easy instruction how to install ruby and how to check.

ok - yes, this is the easiest way
for you to test the Output Pane in HE,
with this simple Ruby script.

3 Steps:
--------
1)  Install Ruby in Win 32 (easy - 20 seconds!):
       - http://rubyinstaller.org/downloads   
          1.9.3-p194 = latest version.

2)  Type: 
          ruby -v in DOS window,
      to confirm install ok.

3)  Paste into HE, this simple Ruby script:

taxrate = 0.175
print "Enter price: "
s = gets
subtotal = s.to_f   #converts "s" string to float
tax = subtotal * taxrate
print "\nTax on $#{subtotal} is $#{tax}, so grand total is $#{subtotal+tax}"

with these HE Tool settings:
   Title:              RubyDO
   Command:    Ruby
   Arguments:   %MainFilePath%

3) The script should 1st ask you for a price,
     but... it does NOT show the "Enter price: " prompt!.
       - Anyhow, type :
               333  and <Enter> key,
         even if you do not see "Enter price: ".

       - script then prints tax result correctly in Output Pane:
             "Tax on $333.0 is $58.275, so grand total is $391.275"

The Problem:
    -  The "Enter price: " prompt is shown only AFTER you enter: 333 <Enter>.
    -  And...the "333" price you entered before, disappears from the Output Pane!
See the problem?

4) If you have HE output to DOS,
    script works great!.

   HE Tool settings for output to DOS: 
       Title:              RubyDOS
       Command:    cmd
       Arguments:   /k ruby %FileName%
       with [ ] Capture Output  UNchecked.

So,
script works great in HE with Tool:  RubyDOS,
but not 100% with Tool:  RubyDO.

By the way, this very simple Ruby script
is taken from "The Book of Ruby" PDF tutorial,
included in the Ruby install you did.
  ==> see Chapter 1, end of page 3.

Alex, hope this helps you test it.

SFdude
XP-Pro SP3 32bit
ruby 1.9.3p194 (latest)

alex

Thanks a lot Ray for detailed explanation!
Have not test it yet, but will do. And will fix, if will be able, of course.

HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

alex

Hi Ray,

I have checked.
1) The reason to output, delayed till user input, is ruby itself and your program. HE catches data sent to standard output by tool, but Ruby does not do that. It caches the output until user input comes and flushes it only on program exit. To verify that, just place STDOUT.flush before s = gets .
2) Second problem, is that ruby does not output input, a other console programs doing. Maybe because once more because of some optimization. Here I can help, providing flag for echo input (disabled by default) in next alpha.

BR, Alex.
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

SFdude

Hi Alex,

>> It caches the output until user input comes and flushes it only on program exit....
      Hmmm...yes, that's what I thought...
      Right now, it's only an OUTPUT Pane,
      no user INPUT is shown.

>> Here I can help, providing a *** flag for echo input *** (disabled by default) in next alpha.
      That would be GREAT if you can do that,
      and echo any user INPUT. Yes!

      After all, people try out many Scripts in HE,
      where users actually type INPUT, (as well as read OUTPUT)...
     
     Echo User INPUT in the Output Pane (next version),
     would make HE even +powerful and awesome!! 
     Go for it, Alex!!  :-)



alex

As I wrote, normally tools integrated in HE echo input by themselves. So, I need explicitly delete what user has typed before sending command to tool.
Only RUBY does not do that.
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

SFdude

#9
Understood.

I was simply referring to the new Output Pane
     "Flag echo input",
which you mentioned adding to HE :
>> Here I can help, providing a *** flag for echo input *** (disabled by default)
>> in next alpha.

Adding that "echo input Flag" to next HE version,
would be really helpful.

Again Alex, thanks for writing HE!
(really great f/ editing Ruby and Awk scripts ...).
Love it!