简体   繁体   English

在 sbt shell 中设置环境变量

[英]Setting an environment variable from within the sbt shell

I would like to be able to set an environment variable from within the interactive sbt shell, and I can't seem to find a way to do that.我希望能够从交互式 sbt shell 中设置环境变量,但我似乎无法找到一种方法来做到这一点。 (I have looked on the official sbt docs as well as on stackoverflow without success). (我查看了官方 sbt 文档以及 stackoverflow 都没有成功)。

I want to make it clear that I don't want to have to set this environment variable in the build.sbt file, but rather be able to change it on the fly on my interactive sbt shell session, so that the environment variable is used for the next sbt commands I run.我想明确表示我不想build.sbt文件中设置这个环境变量,而是能够在我的交互式 sbt shell 会话中即时更改它,以便使用环境变量对于我运行的下一个 sbt 命令。

For example, I would like to be able to do something like (from within the sbt shell):例如,我希望能够执行以下操作(从 sbt shell 中):

> set_environment_variable("foo", "foo_value")
> `mymodule`/run
> (... program runs and completes)
> set_environment_variable("foo", "another_foo_value")
> `mymodule`/run

Is this possible?这可能吗? And if it is, how can I do it?如果是,我该怎么做?

Using sbt 0.13.15 the only thing I've found which has worked for me is to use eval .使用 sbt 0.13.15我发现唯一对我有用的是使用eval

> eval System.setProperty("foo", "foo_value")
> `mymodule`/run
> ...
> eval System.setProperty("foo", "another_foo_value")
> `mymodule`/run

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM