@nicolas.estrada938 Decided to add support to bb for this trailing map and StackTraceElement. I'm building a new bb version now
I also tested omniconf and it worked after those fixes
You my friend are a saint! ๐
Babashka 0.4.4 is released. Changes: https://github.com/babashka/babashka/blob/master/CHANGELOG.md#044
Fun side effect of including StackTraceElement in bb is that you can inspect some of bb/sci's runtime ;)
$ bb -e '(->> (try (/ 1 0) (catch Exception e (.getStackTrace e))) (map bean) clojure.pprint/print-table)'
| :classLoaderName | :fileName | :moduleVersion | :nativeMethod | :className | :moduleName | :class | :lineNumber | :methodName |
|------------------+------------------+----------------+---------------+-----------------------------------------+-------------+-----------------------------------+-------------+--------------|
| | Numbers.java | | false | clojure.lang.Numbers | | class java.lang.StackTraceElement | 188 | divide |
| | core.clj | | false | clojure.core$_SLASH_ | | class java.lang.StackTraceElement | 1029 | invokeStatic |
| | core.clj | | false | clojure.core$_SLASH_ | | class java.lang.StackTraceElement | 1022 | invoke |
This is pretty cool too. Get info about another process:
$ bb -e '(.info (.get (java.lang.ProcessHandle/of 39045)))'
#object[java.lang.ProcessHandleImpl$Info 0x6bd723ed "[user: Optional[borkdude], cmd: /Applications/Emacs.app/Contents/MacOS/Emacs-x86_64-10_14, startTime: Optional[2021-05-28T08:59:27.973Z]]"]
so with this you can get command line arguments, the exact binary location of what the process was started with, arguments, etc
There is supposed to be an alternative to clojure.java.shell/sh
in babashka. What is it called?
And can I do (bb/sh "ecco my command is just a string")
with it? (clojure.java.shell/sh "echo hi")
fails with
Execution error (IOException) at java.lang.ProcessImpl/forkAndExec (ProcessImpl.java:-2).
error=2, No such file or directory
I do not want to split my command string into whitespace as that might not be easy "ecco 'hi there'"
:
(clojure.java.shell/sh (clojure.string/split "echo 'hi there'" #" "))
Execution error (IllegalArgumentException) at clojure.java.shell/parse-args (shell.clj:47).
No value supplied for key: ["echo" "'hi" "there'"]
With apply
it works. But I wonder whether this might ever break a command line string.
@endrebak The alternative in babashka is babashka.process/process
The same library has a function called tokenize
to split shell functions for you
If you want to invoke a shell command just like how you could do it in the shell, streaming output directly to stdout/stderr, then you could also use (babashka.tasks/shell "echo 'hi there'")
user=> (do @(babashka.tasks/shell "echo 'hi there'") nil)
hi there
nil
2000+ stars! https://github.com/babashka/babashka/stargazers :star-struck:
Well deserved! Congrats!
Syntax error (ClassNotFoundException) compiling at (*cider-repl code/myapp:localhost:56301(clj)*:32:12).
babashka.tasks
My lein coords are:
[babashka/babashka "0.4.4"]
Also tried:
(require '[babashka.impl.tasks :as tasks])
Syntax error (IllegalArgumentException) compiling . at (borkdude/deps.clj:196:12).
More than one matching method found: newFileSystem
Hmm, babashka isn't really supposed to be used as a JVM project. I was assuming you were using babashka as a tool
But the libraries contained in there, such as babashka.process, are available on the JVM
Cool!
It seems like clojure.java.shell/sh
does not support many simple commands like:
(clojure.java.shell/sh "sleep" "1" ";" "echo" "2")
;; => {:exit 1, :out "", :err "usage: sleep seconds\n"}
So I'll be looking into babashka :thumbsup:The problem there is that ";"
is bash syntax
if you want to invoke bash, you could invoke bash
with e.g. bash -c "echo hello"
Thanks ๐
So this now works @ben.sless
{:tasks
{:init (do (def ^:dynamic *java*)
(def ^:dynamic *browser*))
test-front-end (println :browser *browser*)
test-back-end (println :java *java*)
test-app {:depends [test-front-end test-back-end]}
run-matrix (doseq [java [8 11]
browser ["Safari" "Chrome" "Firefox"]]
(binding [*java* java
*browser* browser]
(run 'test-app)))}}
The previous issues are fixed.First, that's pretty cool, ngl, going to try it out
Second, have you had a chance to give some thought to my suggestion regarding adding a :matrix
key to tasks? I'm willing to donate a hammock ๐
Haven't thought through the matrix yet ;)