Fork me on GitHub
#babashka
<
2022-08-24
>
erwinrooijakkers13:08:43

If I run rsvg-convert icon.svg -w 60 -h 60 > icon.png in the terminal it works fine, but in Babashka using (println @(babashka.process/sh "rsvg-convert icon.svg -w 60 -h 60 > icon.png")) I get:

$ ./convert.clj
{:proc #object[java.lang.ProcessImpl 0x6354d321 Process[pid=93508, exitValue=1]], :exit 1, :in #object[java.lang.ProcessImpl$ProcessPipeOutputStream 0x759aca59 java.lang.ProcessImpl$ProcessPipeOutputStream@759aca59], :out , :err Multiple SVG files are only allowed for PDF and (E)PS output.
, :prev nil, :cmd [rsvg-convert icon.svg -w 60 -h 60 > icon.png]}
So somehow it sees multiple SVG files as input. Any ideas how to escape properly?

borkdude13:08:44

process doesn't invoke a bash shell, > is bash syntax

erwinrooijakkers13:08:34

Thanks, I see, this is the signature for rsvg-convert, is there a way to mimick th behaviour of >?

borkdude13:08:14

yes, with :out ... you can redirect the output to another file

erwinrooijakkers13:08:27

amazing thanks, I’ll give it a shot

erwinrooijakkers13:08:27

replacing > icon.png with {:out "icon.png"} works

🎉 2
erwinrooijakkers13:08:56

Maybe it’s the >?

vollcheck15:08:33

hi, I probably found minor bug but wanted to consult it: if you look into the result of babashka.tasks/shell you will bump into something like following map:

{:proc ,,,
 :exit 0,
 :in
 #object[java.lang.ProcessBuilder$NullOutputStream 0x38a945bb "java.lang.ProcessBuilder$NullOutputStream@38a945bb"],
 :out
 #object[java.lang.ProcessBuilder$NullInputStream 0x84675d3 "java.lang.ProcessBuilder$NullInputStream@84675d3"],
 :err ,,,
 :prev ,,,
 :cmd ,,,}
and if you look closely :in has NullOutputStream and :out has NullInputStream. Shouldn't they be the other way around?

borkdude15:08:25

Nope but I can understand that this confuses you :)

vollcheck15:08:11

yeah, I did slurp on both and from those two only :out can be slurped

vollcheck15:08:20

whiiiich makes sense

lispyclouds15:08:40

what helps me is thinking of this as a handle which you get back. to write to it you would send to the stdin of the process but to write you need an outpustream. same the other way round when you wanna read from it

👍 1
lispyclouds15:08:53

you can only read from an inputstream but its the stdout of the process. hence the confusion i guess

hlship23:08:35

Q: When I see an exception, it seems to omit a lot of relevant stack ... (stacktrace omitted) There's a bunch of stack frames between impl/dispatch and process/check. Is there anything weird about invoking a Var rather than a function that could cause this? (dispatch is passed a map of name to Var, chooses one, then invokes the Var ... perhaps a deref there would help?).

borkdude01:08:43

Would you mind moving the stacktrace from the channel to a gist in order to not "flood" the channel? I'll get back to your question when I'm properly awake tomorrow ;)

borkdude16:08:10

so, how stacktrace (currently) works in SCI is every call location is recorded in a nested try/catch at analysis time and when an exception happens, this try/catch is unwinded. but this only works for calls that can be statically seen

borkdude16:08:29

so calls that are made dynamically unfortunately aren't part of this mechanism

👀 1
hlship19:08:55

Ouch! Is there an API that my code can use that inform SCI about the call?

borkdude19:08:37

not currently

borkdude19:08:58

So for example:

(defn foo []
  (/ 1 0))

(defn bar []
  (foo))

(bar)
gives:
clojure.core// - <built-in>
user/foo       - /tmp/dude.clj:2:3
user/foo       - /tmp/dude.clj:1:1
user/bar       - /tmp/dude.clj:5:3
user/bar       - /tmp/dude.clj:4:1
user           - /tmp/dude.clj:7:1

borkdude19:08:34

but:

(defn foo []
  (/ 1 0))

(defn bar []
  (foo))

(apply bar [])
gives:
clojure.core//     - <built-in>
user/foo           - /tmp/dude.clj:2:3
user/foo           - /tmp/dude.clj:1:1
user               - /tmp/dude.clj:5:3
clojure.core/apply - <built-in>
user               - /tmp/dude.clj:7:1

borkdude19:08:49

because the bar call wasn't visible as a function call

borkdude19:08:11

and apply is just the native apply function which bypasses SCI