Fork me on GitHub
#babashka
<
2023-11-15
>
Yuhri Graziano Bernardes00:11:22

Hi everyone! I'm using babashka process in a CLI of mine and I'd like to know if there's a way to detach the process from the current shell so I can run commands that while to finish in background. I tried some solutions like append &! at the end of my command but it didn't work. For now I'm just appending "&!" to my CLI calls from terminal, but I'd like to do that through code.

lukasz00:11:17

Just to clarify: do you want to start the process and just let it run without checking if it's alive? Or do you want to spawn a process, monitor it in a background while doing other work?

lispyclouds08:11:34

if youre trying to start a process which is forked off you can use https://github.com/babashka/process/blob/master/API.md#babashka.process/process which returns a running Process object whcih can be interacted with. Also FYI, the & at the end is a bash/shell syntax, OS specific and not related to the Process itself.

Yuhri Graziano Bernardes13:11:11

@U0JEFEZH6 @U7ERLH6JX I want to spawn the process and let it run. I'm using process but i don't want to block my current session. For now, I'm running my CLI like my-cli sub command &!. But I want to run it as my-cli sub command but the process I spawn with process just die when babashka "quits"

borkdude13:11:41

AFAIK process/process doesn’t block and detaches

borkdude13:11:03

Just do use shell or sh

borkdude13:11:08

Don’t I mean

lispyclouds13:11:32

@U0132G7Q29X this works:

(require '[babashka.process :as p])

;; fork off the ls process here. non blocking
(def ls (p/process "ls" "-alh"))

; ... do other stuff here

lispyclouds13:11:27

you can have some long running process there

borkdude13:11:52

I think he wants to keep the process running when bb quits so another examples would be needed to illustrate that

👍 1
borkdude13:11:15

Eg spawn another bb which prints something every second

Yuhri Graziano Bernardes14:11:48

That's it @U04V15CAJ! I'll try to explain my use case: 1- In my project I have some shellscripts that execute a lot of stuff, like download huge files 2- The CLI i've built with babashka prepare a lot of stuff to call this script properly (e.g. envars, config files, validations, etc) 3- Call the shellscript through babashka.process/process I wanted to execute step 3 and keep it running even when bb quits I don't know if this is helpful somehow. Ty for your help

borkdude15:11:16

@U0132G7Q29X As you can see in this example, child bb keeps running while the parent bb quits after two seconds.

bb -e '(babashka.process/process {:inherit true} "bb -e \"(while true (Thread/sleep 1000) (prn :hello))\"") (Thread/sleep 2000)'

😮 1
grounded_sage09:11:37

Has anyone done a static site generator using Babashka?

jackrusher10:11:16

Several of my personal and project sites use bb too 🙂

escherize16:11:07

the “landing page” for my home server is generated from bb and huff. It lists 15ish categorized links to services I run here at home

escherize16:11:57

Anyone else look at templating languages and marvel at how inelegant they are compared to hiccup-life?

yes 1
grounded_sage17:11:47

I built my current website using Eleventy about 3-4 months ago. I opened it up to change some to change something a couple of days ago and couldn’t figure it out. 😆

Oliver Marks18:11:18

I seem to remember there was a library for doing fancy cli tools is that for babashka or was it nbb or something ? can't remember the name 😕

borkdude18:11:10

clojure.tools.cli is also built-in

borkdude18:11:21

there's various other options available via external libs

Oliver Marks18:11:21

yeah I am thinking of something else todo progress bars or live reactive updating on atom changes or maybe i imagined it 😛

Oliver Marks19:11:47

ink was the library I was trying to remember but I will look at both options, cheers

skynet21:11:22

is it possible so suppress SSH banner printing when using bbssh?

Crispin08:11:15

@U0DSU64Q1 I do not have ssh Banner setup on any of my SSH servers. Thus I don't see this. I will try setting up a banner and see if I can replicate, and if so open a ticket.