Fork me on GitHub
#babashka
<
2022-01-13
>
Benjamin09:01:54

what is the best way to start a long running shell command in the background / async? (async/go (shell/sh "sh" "pretend-server.sh")) ?

borkdude09:01:50

@U02CV2P4J6S You can just use babashka.process directly for this which is already async:

(require '[babashka.process :refer [process]])

(process ["sh" "pretend-server.sh"] {:inherit true})

teodorlu10:01:21

Yes - nice indeed. Babashka terminates, but the process keeps running. Like cmd &; disown.

#!/usr/bin/env bb

(require '[babashka.process :refer [process]])

(process ["bash" "-c" "sleep 5 && echo done"] {:inherit true})
bb finishes up, done is printed to the terminal afterwards.

mknoszlig10:01:22

is there a good way to determine what platform a babashka script is being run on (windows/linux/etc) ?

borkdude10:01:38

@maximilian babashka now has babashka.core/windows?

mknoszlig10:01:17

oh, that’s perfect, thanks 🙂

borkdude10:01:52

and there is (System/getProperty "os.name")

Benjamin15:01:14

Type:     java.util.MissingResourceException
Message:  Could not load any resource bundle by com.sun.org.apache.xerces.internal.impl.msg.XMLMessages
jo when I use xml from inside babashka/babashka:0.5.0-alpine docker

borkdude16:01:37

Can you try with 0.7.3? Not sure if that helps, but then we have a baseline

borkdude16:01:53

Do you have a repro in code for this? Does it happen only on Alpine?

lispyclouds16:01:16

@U02CV2P4J6S try with 0.7.1 alpine if youre trying docker. theres an issue in our CI which hasnt pushed the docker images for 0.7.2 and 0.7.3 alpine

Benjamin16:01:12

Step 1/4 : from babashka/babashka:0.7.1-alpine
manifest for babashka/babashka:0.7.1-alpine not found: manifest unknown: manifest unknown
@U7ERLH6JX do I put the version wrong?

lispyclouds16:01:50

ah sorry 0.7.0

borkdude16:01:12

yeah this one works for me:

$ docker run --rm babashka/babashka:0.7.0-alpine bb -e "(+ 1 2 3)"
6

borkdude16:01:16

now with the repro?

lispyclouds16:01:26

theres no 0.7.1

Benjamin16:01:41

#xml/element{:tag :testsuites, :attrs {:name "jest tests", :tests "2", :failures "1", :errors "0", :time "0.23"}, :content ["\n  " #xml/element{:tag :testsuite, :attrs {:name "undefined", :errors "0", :failures "1", :skipped "0", :timestamp "2022-01-13T16:23:28", :time "0.203", :tests "2"}, :content ["\n    " #xml/element{:tag :testcase, :attrs {:classname " adds 1 + 2 to equal 3", :name " adds 1 + 2 to equal 3", :time "0.016"}, :content ["\n    "]} "\n    " #xml/element{:tag :testcase, :attrs {:classname " rand is 1", :name " rand is 1", :time "0.002"}, :content ["\n      " #xml/element{:tag :failure, :content ["Error: expect(received).toBe(expected) //  equality\n\nExpected: 1\nReceived: 0.12556658976995672\n    at Object.<anonymous> (/home/benj/repos/js/gitlab-ci-tests-demo/sum.test.js:9:25)\n    at Promise.then.completed (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/utils.js:391:28)\n    at new Promise (<anonymous>)\n    at callAsyncCircusFn (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/utils.js:316:10)\n    at _callCircusTest (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/run.js:218:40)\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at _runTest (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/run.js:155:3)\n    at _runTestsForDescribeBlock (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/run.js:66:9)\n    at run (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/run.js:25:3)\n    at runAndTransformResultsToJestFormat (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)"]} "\n    "]} "\n  "]} "\n"]}
bit unvieldy can try to narrow it down further
(require '[clojure.data.xml :as xml])

(and (xml/parse-str
      "<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>")


     (xml/parse-str
      (slurp "junit.xml")))
content of junit:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="jest tests" tests="2" failures="1" errors="0" time="0.23">
  <testsuite name="undefined" errors="0" failures="1" skipped="0" timestamp="2022-01-13T16:23:28" time="0.203" tests="2">
    <testcase classname=" adds 1 + 2 to equal 3" name=" adds 1 + 2 to equal 3" time="0.016">
    </testcase>
    <testcase classname=" rand is 1" name=" rand is 1" time="0.002">
      <failure>Error: expect(received).toBe(expected) //  equality

Expected: 1
Received: 0.12556658976995672
    at Object.<anonymous> (/home/benj/repos/js/gitlab-ci-tests-demo/sum.test.js:9:25)
    at Promise.then.completed (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/utils.js:391:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/utils.js:316:10)
    at _callCircusTest (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/run.js:218:40)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at _runTest (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/run.js:155:3)
    at _runTestsForDescribeBlock (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/run.js:66:9)
    at run (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/home/benj/repos/js/gitlab-ci-tests-demo/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:170:21)</failure>
    </testcase>
  </testsuite>
</testsuites>

borkdude16:01:52

@U02CV2P4J6S With 0.7.0 I get:

$ docker run --rm -v $PWD:/tmp babashka/babashka:0.7.0-alpine  bb /tmp/script.clj
#xml/element{:tag :testsuites, :attrs {:name "jest tests", :tests "2", :failures "1", :errors "0", :time "0.23"}

borkdude16:01:58

so it seems to work there

Benjamin16:01:22

sec I guess it's fine lul

Benjamin16:01:28

I read "error" xd

borkdude16:01:30

also works on 0.5.0 for me

borkdude16:01:02

if you can make a repro in a github repo or so including the docker command, then I can try again

Benjamin16:01:28

indeed for me too. Then the difference was that I ran it with a gitlab runner - will try with 0.7.0 to check

Benjamin17:01:00

ok it worked with 0.7.0 for some reason

Benjamin17:01:03

so all good

borkdude17:01:10

good to hear!

bananadance 1
borkdude17:01:17

thanks for reporting back

pinkfrog16:01:12

Can I hide the output when a process finishes?

{:proc #object[java.lang.ProcessImpl 0x2d8bcb "Process[pid=6547, exitValue=0]"], :exit 0, :in #object[java.lang.ProcessBuilder$NullOutputStream 0x48c6e255 "java.lang.ProcessBuilder$NullOutputStream@48c6e255"], :out #object[java.lang.ProcessBuilder$NullInputStream 0x60a9b89 "java.lang.ProcessBuilder$NullInputStream@60a9b89"], :err #object[java.lang.ProcessBuilder$NullInputStream 0x60a9b89 "java.lang.ProcessBuilder$NullInputStream@60a9b89"], :prev nil, :cmd ["clojure" "-X:dev" "flyway/migrate"]

Benjamin16:01:30

(do (proc...) nil) bb prints the return of the last form always

☝️ 1
Perry20:01:53

Hello! First time in the channel. I'm dropping in to inquire about some bb behavior we ran into in the last couple days re: CLI-argument handling.

Perry20:01:41

It concerns how -- is interpreted when calling a namespace's -main via bb --main.

Perry20:01:47

I see a change in behavior at version 0.6.5, which is that -- is passed as the first argument to the -main, rather than being interpreted as a separator. See below for illustration

Perry20:01:01

$ cat f.clj
(ns f)

(defn -main [& args] (prn args))

$ cat test.sh
#!/bin/sh
VERSION=${1:-0.7.1}
echo $VERSION

docker run -v `pwd`:`pwd` -w `pwd` --rm -it babashka/babashka:${VERSION} bb -cp . --main f -- hi

$ for version in 0.3.0 0.4.0 0.5.0 0.6.0 0.6.1 0.6.2 0.6.3 0.6.4 0.6.5 0.6.6 0.6.7 0.6.8; do sh test.sh $version; done
0.3.0
("hi")
0.4.0
("hi")
0.5.0
("hi")
0.6.0
("hi")
0.6.1
("hi")
0.6.2
("hi")
0.6.3
("hi")
0.6.4
("hi")
0.6.5
("--" "hi")
0.6.6
("--" "hi")
0.6.7
("--" "hi")
0.6.8
("--" "hi")

Perry20:01:53

This caused us some breakage as we moved past the 0.6.5 version. I'm wondering if this was intended behavior or the consequence of some other change. Thanks!

Perry20:01:26

(@U0EHU1800 helped me narrow this down, BTW)

borkdude20:01:06

@U02TYRYJC6N Thanks for reporting. I think this is a glitch which should be fixed in bb.

borkdude20:01:37

Can you make an issue about it?

Perry20:01:01

Thanks @U04V15CAJ, absolutely will do. Is the above sufficient for the description in the issue, or is there anything else you'd like added?

borkdude20:01:10

yes, it's sufficient

Perry21:01:12

Thanks again!