Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying environment variable for a process with scala.sys.process?

Tags:

scala

I want to run my process from scala, with several environment variables modified. For example:

Seq("bash","echo $asdf") !

and $asdf set to some value. Is there a way to do this from scala?

EDIT:

The closest I got to it so far:

val pb = new java.lang.ProcessBuilder("bash","echo $asdf")
pb.environment.put("asdf","value") }
val p = pb.start()
io.Source.fromInputStream(p.getInputStream).getLines.toList.foreach(println)
p.waitFor()

But this is ugly.

like image 529
Rogach Avatar asked Feb 25 '12 10:02

Rogach


People also ask

How do I set an environment variable in Scala?

Step 2: Set Your Java EnvironmentAppend the full path of Java compiler location to the System Path. Append the String "C:\Program Files\Java\jdk1. 7.0_60\bin" to the end of the system variable PATH. Execute the command java -version from the command prompt as explained above.

How do I set Environment Variables in SBT?

Then to easily add the environment variable, open the windows menu then type environment, and pick the first option: That takes you directly to the advanced system properties dialog: Then just pick Environment Variables, and paste the copied path in to your PATH.

How do you set an environment variable globally?

Search and select System (Control Panel). Click on the Advanced system settings link and then click Environment Variables. Under the section System Variables, select the environment variable you want to edit, and click Edit. If the environment variable you want doesn't exist, click New.


1 Answers

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

See Process.

like image 129
Daniel C. Sobral Avatar answered Oct 15 '22 07:10

Daniel C. Sobral