Fork me on GitHub
#babashka
<
2024-01-09
>
Omer ZAK14:01:05

I am a beginner with Babashka. I have a series of operations which I repeat each day. I decided to write a Babashka script to automate those operations. One of the operations is to start Emacs editing a file, as a separate process (i.e. with '&' at end when using bash). My question is - how to tell Babashka to start an independent process and eventually finish the script WITHOUT waiting for Emacs to exit? The bash script which I want to run under Babashka is:

echo Starting a True session
xdg-open 
emacs --geometry 80x50+1940+16 ~/work/on-the-truth.txt & # I do not know how to formulate it in Babashka-Clojure.
egrep -i big.*lies ~/work/mixed.txt

borkdude14:01:22

Hey welcome. You can do this by launching the process asynchronously with:

(babashka.process/process "the-process" "arg1" "arg2")

Omer ZAK14:01:25

And my script will terminate without waiting for "the-process" to finish first?

borkdude14:01:47

Ah btw, you need to provide some more args, let me test it

borkdude14:01:33

I expected this to work:

(babashka.process/process {:inherit true} "emacs" "some-file")
It does for most command line programs

borkdude15:01:26

which OS are you using?

borkdude15:01:31

This works for me on macOS:

(babashka.process/shell "open" "-a" "emacs" "/tmp")
(println "Hello")

borkdude15:01:41

xdg-open would work in your case, but only if you're able to pass it a preferred application

Omer ZAK15:01:42

I use Linux (Debian Bullseye). Turns out that the following worked for me without the need for any special arguments.

(process "emacs" "--geometry" "80x50+1940+16" "/home/omer/work/on-the-truth.txt")
By the way, xdg-open worked for me without special preparations. It seems to recognize my desktop-configured default browser. So, my first actual Babashka script works! (and the directory which hosts it has no *.edn files) Thanks for your help!

borkdude15:01:16

Nice!

👍 1
Mateusz Mazurczak16:01:19

I have weird issue with babashka fs, when I try to use fs/copy, it throws an error "java.nio.file.FileSystemException" "/pom.xml: Read-only file system". I'm using mac and it has all the rights to write, also manully or through console cp works without a problem for this file. Any ideas?

Bob B16:01:58

It's somewhat guess work with no code, but judging by the message, it looks like it might be trying to write to pom.xml in the root directory (of the whole system), i.e. not a relative path. Is that the desired effect?

Mateusz Mazurczak16:01:20

@U013JFLRFS8 Oh wow, so simple, thank you very much!

👍 2