Scala:无法设置环境变量 [英] Scala: Unable to set environment variable

查看:261
本文介绍了Scala:无法设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友

我试图在我的Scala shell中设置环境变量"asdf",如

I'm trying to set the environment variable "asdf" in my Scala shell, as described here

这些是我的命令:

scala> import scala.sys.process.Process
import scala.sys.process.Process

scala> Process(Seq("bash", "-c", "echo $asdf"), None, "asdf" -> "Hello, world!").!
Hello, world!
res18: Int = 0

但是当我尝试读回环境变量时:

But when i try to read the environment variable back:

scala> sys.env.get("asdf")
res19: Option[String] = None

输出显示无".如何在当前会话中正确设置环境变量 ?

The output says "None". How do i properly set my environment variable in the current session?

PS-请不要对此表示否决;我真的很努力,但是无法解决我的问题

PS - Please do not downvote this; i'm trying really hard but unable to get past my issue

推荐答案

与Scala无关,您只是误解了情况.行尾的地图

It has nothing to do with Scala, you are just misunderstanding the situation. The map at the end of the line

scala> Process(Seq("bash", "-c", "echo $asdf"), None, "asdf" -> "Hello, world!").!

不会更改您正在键入的 进程的环境;它会更改Process()函数创建的子进程的环境.

doesn't change the environment of of this process, the one you are typing into; it changes the environment of the child process that the Process() function creates.

这篇关于Scala:无法设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆