struggling a bit to get the output of a ProcessBuilder
workflow (my Java is weak)
(defn find-files! []
(let [proc (-> (ProcessBuilder. ["find" "./some-dir"])
(.redirectOutput ProcessBuilder$Redirect/INHERIT)
(.redirectError ProcessBuilder$Redirect/INHERIT)
(.start))
proc-input (.getOutputStream proc)]
(into [] ????)))
(ripped off from https://github.com/borkdude/babashka/blob/master/examples/process_builder.clj)
@goomba Not sure where you're going with that example: you want to feed input to the process?
It's probably safe to assume that I'm totally misunderstanding ProcessBuilder and the output streams. My goal here is to capture the output of a long running process, like a large "git clone", and capture the output into a string or a vector of strings.
In some previous work I tried using shell/sh
, but it doesn't seem suitable for long running tasks
I tried looking into the Java API for how to work with the redirects of the ProcessBuilder but I got lost in the sauce
yeah, let me try to write that
What's not clear in your example: would like also to feed input to that process?
And why do you redirect output? This means it will be sent straight to stdout
(require '[<http://clojure.java.io|clojure.java.io> :as io])
(defn find-files [path]
(let [proc (-> (ProcessBuilder. ["find" path])
(.start))
output (.getInputStream proc)]
(future
(run! prn (line-seq (io/reader output))))))
@(find-files (first *command-line-args*))
$ bb /tmp/foo.clj /tmp/version-clj
"/tmp/version-clj"
"/tmp/version-clj/test"
"/tmp/version-clj/test/cljx"
"/tmp/version-clj/test/cljx/version_clj"
...
Confusingly, you get the output of the process using .getInputStream
because it returns an inputstream
You might also want to read this: https://book.babashka.org/#child_processes
sweet! thank you
This is an in progress library which should make all of this easier: https://github.com/babashka/babashka.process
You can also take a look at https://github.com/babashka/babashka.process
Any thoughts on this discussion? https://github.com/http-kit/http-kit/issues/442#issuecomment-690040016. If you have, consider posting your thoughts there.
I also made a #http-kit channel now
I've added a simple example of using Babashka to rewrite an existing bash script into Clojure to perform spotifyd notifications on Linux: https://github.com/dharrigan/spotifyd-notification
Cool! Feel free to add to https://github.com/borkdude/babashka/blob/master/doc/libraries.md which also features projects
kk
done
thanks!
np
Curious about techniques for Babashka applications-as-scripts.
For instance, I created two files, config.clj
and core.clj
(which requries config.clj
with a deps.edn
and the traditional project structure. However from a non-root directory when I tried bb -f ../path/to/src/core.clj
, I got the cannot find my-project.config.clj
error message
If I wanted to have a more complex setup but still use it as a script, would I be looking at making an Uberjar?
Either an uberscript or uberjar yes
@goomba or put the dir with the scripts on the classpath correctly using -cp
root dir?
that has the deps?
I gotta tell you @borkdude this damn project is so much damn fun hahaha
Good to hear :)
So if your sources are in <project>/src
then classpath should be src
, but you then go into ..
then your classpath should become <project>/src
but maybe using absolute paths for that is the least confusing
understood. So regardless of what location I'm in, if I set the -cp
to the src
of the project (relatively or absolutely, as long as it is correct). Does that mean then that if I have src/project_name/*.clj
files, and the namespaces are (ns project-name.something)
, it should still be src
?
no, you can put it anywhere you want, and make the classpath anything you want
to be more specific:
$ tree
.
βββ deps.edn
βββ Makefile
βββ src
βββ react_deployment
βββ config.clj
βββ core.clj
so still point to src
with the classpath?
you can also make the classpath the current directory and have no src dir for example
foo/bar.clj becomes (ns foo.bar) yes.
perfect
yep that did it
I can't wait to try out some crazy socket/async stuff
Hey,
I have been writing a bit of babashka lately (itβs absolutely amazing btw) I was wondering what was the best way to interact with AWS with babashka. I have been doing some stuff with generating and running commands with clojure.java.shell
but I was wondering if there was a way to either use the java sdk or if a library to integrate with the AWS api or something (couldnβt find something here https://github.com/borkdude/babashka/blob/master/doc/libraries.md)
(or would that be a good candidate for a pod or something ?)
@thomas.ormezzano It's been asked a couple of times before. I think you could maybe wrap the aws using clojure.java.shell or maybe create a pod around the Python AWS SDK.
This is an example of a pod in Python: https://github.com/babashka/babashka.pods/blob/master/examples/pod-lispyclouds-sqlite/pod-lispyclouds-sqlite.py
ok amazing thank you will take a look at this :thumbsup:
very interesting idea to write an AWS pod in another language, maybe Go would be a good candidate too
Yes, Go would also be a good candidate, since it also compiles to native and should have very good startup
I'm not using AWS myself that much, so I'm leaving this one up to the babashka community :)
And where I can I'll try to help of course
This is v. relevant to something I'll be working on soon, no promises but I might tackle this
aws pod
or something like that
I did some hack with lambda, attaching babashka and awscli layers, shelling to aws cli worked nicely, although awscli is a python thing so not that stand-alone, compared to go
@lukaszkorecki The pod could live under the babashka org when it's more or less done, if you wanted to. Also ok to keep it under your company org, etc.
@borkdude I'm still at the gathering requirements stage, so it's not been fully decided if we're going to go with Clojure (jvm) or BB. But if we go with BB, it's def going to be open source
Could be both. If you're going with the JVM library and make it GraalVM compatible, it could also be wrapped in a pod
True! I'll keep you updated and bug you with questions ;-)
:thumbsup:
Have you guys seen this? I am using it for some minor stuff but it's got the entire set of services for AWS. https://github.com/cognitect-labs/aws-api