running a ruby script in notepad++

85 views Asked by At

I've pasted the following code in notepad:

puts ("enter a number")
x = gets.to_i
puts ("enter a second number")
y = gets.to_i
result = x + y
puts result

I've also created the following batch file:

@echo off
"C:\Users\Asus\ruby\helloworld.rb" "%1"
pause

When running the prog I get the following response in the command line:

enter a number
C:/Users/Asus/ruby/helloworld.rb:2:in `gets': Invalid argument @ rb_sysopen - $(C:\Users\Asus\ruby\helloworld.rb) (Errno::EINVAL)
        from C:/Users/Asus/ruby/helloworld.rb:2:in `gets'
        from C:/Users/Asus/ruby/helloworld.rb:2:in `<main>'
1

There are 1 answers

3
Andrew On

This works for me on windows:

Make you batch file look like:

@echo off
"C:\your\path\to\ruby.exe" "%1"
pause

Edit a ruby file in Notepad++ and save it. Enter the following in the dialog box from the menu "Run/Run..."

"C:\your\path\to\batchfile.bat" "$(FULL_CURRENT_PATH)"

Alternatively you can call ruby directly from the Run/Run... but you will need to put a pause at the end of your script, eg:

"C:\your\path\to\ruby.exe" "$(FULL_CURRENT_PATH)"

And your code should do something like:

puts "Enter a number"
x = gets.to_i
puts "Enter a second number"
y = gets.to_i
result = x + y
puts "The result of #{x} + #{y} = #{result}"

puts "\nPress enter to exit"
gets

Once you are comfortable with that then maybe set up a Run/Run... to run Rake tasks in your project