如何在 Windows 控制台中设置 RAILS_ENV?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1007589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:38:53  来源:igfitidea点击:

How can I set the RAILS_ENV in a Windows console?

ruby-on-railswindowsrubywindows-xp

提问by Ethan

On Linux and OS X, I'm accustomed to running Rake tasks in specified Rails "environments" by doing this:

在 Linux 和 OS X 上,我习惯于通过这样做在指定的 Rails“环境”中运行 Rake 任务:

$ export RAILS_ENV=monster_island ; rake monsters:destroy_all

How can I do the equivalent if I'm running the task on Windows XP in a Windows console?

如果我在 Windows XP 上的 Windows 控制台中运行任务,我该如何做?

回答by Tai Squared

c:>set RAILS_ENV=monster_island

c:>set RAILS_ENV=monster_island

If you run set without any other arguments, you will see the environment variables that are set. Running set in a console will set that variable for just that console and won't be persisted across sessions or to other consoles.

如果不带任何其他参数运行 set,您将看到设置的环境变量。在控制台中运行 set 将仅为该控制台设置该变量,并且不会跨会话或其他控制台持续存在。

You can also set it permanently in the Control Panel - open System, select Advanced, and then Environment Variables (this may vary slightly depending on your version of Windows).

您也可以在控制面板中对其进行永久设置 - 打开系统,选择高级,然后选择环境变量(这可能会因您的 Windows 版本而略有不同)。

回答by Mish Ochu

Of course you can use 'setX' (instead of simply 'set' if you want the variable to persist between console sessions (and you don't want to navigate through the various screens/tabs in the Control Panel

当然,您可以使用“setX”(而不是简单的“set”,如果您希望变量在控制台会话之间保持不变(并且您不想浏览控制面板中的各种屏幕/选项卡)