How to set environmental variable from Scala? -
i need set environmental variable (path) scala.
i tried this:
val cmd = seq("export", "path='bla'") cmd.lines
but got error:
java.io.ioexception: cannot run program "export": error=2, no such file or directory @ java.lang.processbuilder.start(processbuilder.java:1041) @ scala.sys.process.processbuilderimpl$simple.run(processbuilderimpl.scala:68) @ scala.sys.process.processbuilderimpl$abstractbuilder.lines(processbuilderimpl.scala:140) @ scala.sys.process.processbuilderimpl$abstractbuilder.lines(processbuilderimpl.scala:106) @ .<init>(<console>:12) @ .<clinit>(<console>) @ .<init>(<console>:11) @ .<clinit>(<console>) @ $print(<console>) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ scala.tools.nsc.interpreter.imain$readevalprint.call(imain.scala:704) @ scala.tools.nsc.interpreter.imain$request.loadandrun(imain.scala:914) @ scala.tools.nsc.interpreter.imain.loadandrunreq$1(imain.scala:546) @ scala.tools.nsc.interpreter.imain.interpret(imain.scala:577) @ scala.tools.nsc.interpreter.imain.interpret(imain.scala:543) @ scala.tools.nsc.interpreter.iloop.reallyinterpret$1(iloop.scala:694) @ scala.tools.nsc.interpreter.iloop.interpretstartingwith(iloop.scala:745) @ scala.tools.nsc.interpreter.iloop.command(iloop.scala:651) @ scala.tools.nsc.interpreter.iloop.processline$1(iloop.scala:542) @ scala.tools.nsc.interpreter.iloop.loop(iloop.scala:550) @ scala.tools.nsc.interpreter.iloop.process(iloop.scala:822) @ scala.tools.nsc.interpreter.iloop.main(iloop.scala:851) @ xsbt.consoleinterface.run(consoleinterface.scala:57) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ sbt.compiler.analyzingcompiler.call(analyzingcompiler.scala:73) @ sbt.compiler.analyzingcompiler.console(analyzingcompiler.scala:64) @ sbt.console.console0$1(console.scala:23) @ sbt.console$$anonfun$apply$2$$anonfun$apply$1.apply$mcv$sp(console.scala:24) @ sbt.trapexit$.executemain$1(trapexit.scala:33) @ sbt.trapexit$$anon$1.run(trapexit.scala:42) caused by: java.io.ioexception: error=2, no such file or directory @ java.lang.unixprocess.forkandexec(native method) @ java.lang.unixprocess.<init>(unixprocess.java:135) @ java.lang.processimpl.start(processimpl.java:130) @ java.lang.processbuilder.start(processbuilder.java:1022) ... 35 more
is there other way that?
example doc sys.process.process
:
apply("java", new java.iofile("/opt/app"), "classpath" -> "library.jar")
edit more helpful verbiage:
that is, specify env when spawn child process.
the environment of current process read-only; see system.getenv
, or compare abstractions sys.props
, sys.env
.
the fact shell augments environment bestows on subshells exported variables shell convention. see 3.7.4 in bash reference, example:
on invocation, shell scans own environment , creates parameter each name found, automatically marking export child processes. executed commands inherit environment. export , ‘declare -x’ commands allow parameters , functions added , deleted environment. if value of parameter in environment modified, new value becomes part of environment, replacing old. environment inherited executed command consists of shell's initial environment, values may modified in shell, less pairs removed unset , ‘export -n’ commands, plus additions via export , ‘declare -x’ commands.
this first time answer longer the daniel sobral answer duplicates.
Comments
Post a Comment