This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-09
Channels
- # announcements (2)
- # babashka (11)
- # beginners (9)
- # biff (7)
- # calva (20)
- # catalyst (1)
- # cider (8)
- # clerk (46)
- # clj-kondo (18)
- # clj-otel (2)
- # clojure-brasil (22)
- # clojure-europe (18)
- # clojure-gamedev (23)
- # clojure-italy (5)
- # clojure-nl (2)
- # clojure-norway (14)
- # clojure-uk (6)
- # clr (1)
- # datomic (13)
- # emacs (1)
- # hoplon (13)
- # hyperfiddle (53)
- # introduce-yourself (1)
- # java (23)
- # malli (7)
- # obb (35)
- # off-topic (31)
- # polylith (2)
- # portal (9)
- # rdf (15)
- # reitit (12)
- # releases (3)
- # ring (4)
- # shadow-cljs (6)
- # solo-full-stack (3)
Hey all, I'm learning Babashka and I'm trying to translate the following command scanimage --format=tiff --device-name='airscan:e0:Canon MF230 (USB)' > test.tiff
into bb
I tried the following
(shell/sh
{:out "./item.tiff"}
"scanimage"
"--format=tiff"
"--device-name=airscan:e0:Canon MF230 (USB)")
But I'm getting
----- Error --------------------------------------------------------------------
Type: java.lang.ClassCastException
Message: java.lang.Object[] cannot be cast to java.lang.String[]
Location: /home/adham/pics/photo-album/scan.bb:1:1
----- Context ------------------------------------------------------------------
1: (shell/sh
^--- java.lang.Object[] cannot be cast to java.lang.String[]
2: {:out "./item.tiff"}
3: "scanimage"
4: "--format=tiff"
5: "--device-name=airscan:e0:Canon MF230 (USB)")
6:
----- Stack trace --------------------------------------------------------------
clojure.java.shell/sh - <built-in>
clojure.core/apply - <built-in>
babashka.impl.clojure.java.shell/sh - <built-in>
user - /home/adham/pics/photo-album/scan.bb:1:1
I'm following the https://book.babashka.org/#_shell section on how to output. I also tried {:out "item.tiff"}
with the same result. I do have to note that (shell/sh {:out "file.txt"} "echo hello")
also does not work while (shell/sh "echo" "hello")
does.based on the stack trace, it appears that the script is using clojure.java.shell, which a different API from the shell
funciton in the task API or babashka.process/shell
, so you might want to either use the babashka.process version (since it's presumably a script and not a task), or have a look at the docs for clojure.java.shell/sh
yeah, use babashka.process
, it looks like that is what you wanted based on your arguments
Success!
Thank you both
I've had issues since the book mentions (shell)
as the function in most examples when it is stated that shell
is an alias for clojure.java.shell
. Was I supposed to read the symbol shell
differently in this section of the book?
@U03QTHYKXK7 An alias is not the same as a function name, an alias in Clojure is used to abbreviate a namespace name
Yes, I understand that, the idea is to run something like (shell/sh)
instead of (clojure.java.shell/sh)
. My point and perhaps I was not clear is that copying the code sample in the Shell section which is
(shell {:out "file.txt"} "echo hello")
Throws an exception the with the following
Type: clojure.lang.ExceptionInfo
Message: Could not resolve symbol: shell
My question now is, was I not supposed to copy from the book?@U03QTHYKXK7 Did you read the whole chapter or just one section from the book? That snippet works in babashka tasks but not in a random file
When you are just putting some code in a file, the full example would be:
(require '[babashka.process :refer [shell]])
(shell ...)