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.
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.
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.
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.
Process(Seq("bash", "-c", "echo $asdf"), None, "asdf" -> "Hello, world!").!
See Process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With