且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Ruby:脚本执行后保持控制台打开

更新时间:2023-12-05 18:07:22

似乎您双击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 Enter to return to the shell.