Fork me on GitHub
#babashka
<
2020-07-27
>
dominicm07:07:00

The key thing with exec is that it replaces your process

borkdude07:07:28

Yes, I guess you can't do that with babashka, but ProcessBuilder + inheritIO + System/exit the exit code of that process is the closest thing that comes next probably

johannes.f.knauf14:07:27

I believe this will be hard to do in a portable way, won't it? bash relies on system call https://linux.die.net/man/3/execv to perform the trick. How would that work in Windows?

borkdude14:07:35

ProcessBuilder fulfils this role well enough functionally, although it's not technically the same. So I think we don't need anything new.

grahamcarlyle15:07:25

I've been playing with babashka, and one initial puzzle for me was the printing behaviour

% bb '(:a {:a 3})'
3
% bb '(:b {:a 3})'
%
Is this described in the docs somewhere that i missed, or too obvious to mention? It took my stupid brain a while to work out what was going on

grahamcarlyle15:07:57

so a final nil value doesnt seem to be printed

borkdude15:07:46

@grahamcarlyle nil is not printed. This is because lots of side effects return nil, e.g. (println :foo) and a lot of scripts end in something side-effecting

borkdude15:07:00

So if you really want to print the nil, you can use (prn ..) instead

grahamcarlyle15:07:36

yeah it makes sense, but i didnt realise this behaviour initially and so was puzzled by the absence or presence of output

borkdude15:07:57

I guess it's not properly documented.

borkdude15:07:56

Feel free to make a documentation PR if you wish so

grahamcarlyle16:07:03

i've created a PR for this, hope i created it ok.

borkdude18:07:20

Thanks, merged

grahamcarlyle16:07:48

is there a way of controlling the input/output processing behaviour of bb within a script? so the things that the -o/-O flags would change, i wondered if there was a function i could call to alter the behaviour. My use was a script that in some cases wanted to output text and in other cases EDN.

borkdude16:07:59

In that case I think it's better to just use println and prn. The flags are mostly there for one-liners.

grahamcarlyle17:07:12

i guess another utility of being able to set the flags in a script is when a script could be called via shebang style or as a script

grahamcarlyle17:07:03

as the flags would be in 1 place

borkdude19:07:31

Script from work where we start 2 clojure processes (for building CLJS and less) and 1 boot process (for a JVM Clojure process / REPL) using 1 babashka script: https://gist.github.com/borkdude/8f5dff7c2330ca520403eb44c9013a83. The alternative was to have 3 different tabs open