Fork me on GitHub
#babashka
<
2022-09-08
>
pavlosmelissinos15:09:10

I might be missing the obvious here but how can I set an environment variable from within a babashka REPL? I want to test a function that reads an environment variable (side-effects, yikes, I know, but I can't change it for now) with different values of that variable without starting the REPL every time (or running the namespace as a script)

grazfather15:09:53

It doesn't seem to be easy. You can easily read env with System/getenv but setting the env seems https://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java

lispyclouds15:09:12

you cannot change your own environment from within a script if thats what you want. its a limitation of the JVM and you need to have some native code

borkdude15:09:46

You can however start a new process with an environment variable set

borkdude15:09:57

e.g. spawn another bb instance

grazfather15:09:18

yeah that might be easiest.

pavlosmelissinos16:09:41

TIL, thank you guys. Spawning a new bb process should work, I'd never think of it on my own. 🙂

grazfather15:09:19

Where does shell come from, which I can access in my bb.edn tasks without any require. When I open bb.edn and connect to the nrepl that instance can't find it

borkdude15:09:16

it is from babashka.tasks

grazfather15:09:37

perfect thank you.

grazfather15:09:32

is there some quick and dirty way to eat the exception it raises if its process exits with an error code?

grazfather15:09:33

perfect! thank you!