问题描述
我写了一个像下面例子一样的Ruby脚本。基本功能是相同的:
I wrote a Ruby script like the following example. The basic functionality is the same:
# get input from the user
input = gets.chomp
# do awesome stuf with this input and print the response
puts do_awesome_stuff(input)
The put问题是当我运行脚本时,它会打印我想要的解决方案,但控制台窗口此后立即关闭。我希望控制台保持打开状态。
我目前在Windows上,但是该解决方案应该在每个系统上都可以使用。
The problem is when I run the script it prints the solution I want, but the console window closes right after. I want the console to keep open.I'm currently on windows, but the solution should be working on every system.
一种方法是使用.bat文件运行ruby脚本,然后暂停它,就像这样:
One way is to run the ruby script with a .bat file and pause it, like so:
ruby script.rb
PAUSE
我希望有一种方法不需要附加的.bat文件。
I hope there is a way without the additional .bat file. Does Ruby has a function like PASUE integrated?
推荐答案
似乎您双击ruby脚本文件。
It seems like you double click the ruby script file.
请在 cmd
shell中发出以下命令。
Instead issue the following command in cmd
shell.
ruby filename.rb
如果您不想这样做,可以添加获取
到脚本末尾。
If you don't want that, you can add gets
to the end of the script.
# get input from the user
input = gets.chomp
# do awesome stuf with this input and print the response
puts do_awesome_stuff(input)
gets # <----
但是不建议这样做,因为..如果在cmd shell或终端中运行命令,则应键入额外的返回到外壳程序。
But this is not recommended because .. if you run the command in cmd shell or terminal you should type extra to return to the shell.
这篇关于Ruby:脚本执行后保持控制台打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!