我已将以下代码粘贴到记事本中:
puts ("enter a number")
x = gets.to_i
puts ("enter a second number")
y = gets.to_i
result = x + y
puts result
我还创建了以下批处理文件:
@echo off
"C:\Users\Asus\ruby\helloworld.rb" "%1"
pause
运行 prog 时,我在命令行中收到以下响应:
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>'
这对我在 Windows 上有用:
让你的批处理文件看起来像:
@echo off
"C:\your\path\to\ruby.exe" "%1"
pause
在 Notepad++ 中编辑 ruby 文件并保存。 从“运行/运行...”菜单中的对话框中输入以下内容
"C:\your\path\to\batchfile.bat" "$(FULL_CURRENT_PATH)"
或者,您可以直接从运行/运行...调用 ruby,但您需要在脚本末尾暂停,例如:
"C:\your\path\to\ruby.exe" "$(FULL_CURRENT_PATH)"
你的代码应该做类似的事情:
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
一旦您对此感到满意,那么也许可以设置一个运行/运行...来在您的项目中运行 Rake 任务