Fork me on GitHub
Lone Ranger01:09:50

struggling a bit to get the output of a ProcessBuilder workflow (my Java is weak)

Lone Ranger01:09:13

(defn find-files! []
 (let [proc (-> (ProcessBuilder. ["find" "./some-dir"])
                 (.redirectOutput ProcessBuilder$Redirect/INHERIT)
                 (.redirectError ProcessBuilder$Redirect/INHERIT)
        proc-input (.getOutputStream proc)]
    (into [] ????)))


@goomba Not sure where you're going with that example: you want to feed input to the process?

Lone Ranger13:09:50

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.

Lone Ranger13:09:30

In some previous work I tried using shell/sh, but it doesn't seem suitable for long running tasks

Lone Ranger13:09:07

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 '[ :as io])

(defn find-files [path]
  (let [proc (-> (ProcessBuilder. ["find" path])
        output (.getInputStream proc)]
      (run! prn (line-seq (io/reader output))))))

@(find-files (first *command-line-args*))
$ bb /tmp/foo.clj /tmp/version-clj


Confusingly, you get the output of the process using .getInputStream because it returns an inputstream

❤️ 3

You might also want to read this:

❤️ 3
Lone Ranger13:09:44

sweet! thank you


This is an in progress library which should make all of this easier:


Any thoughts on this discussion? 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:

👍 6

Cool! Feel free to add to which also features projects

Lone Ranger13:09:20

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

Lone Ranger13:09:39

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

Lone Ranger13:09:12

that has the deps?

Lone Ranger13:09:41

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

Lone Ranger13:09:40

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

Lone Ranger13:09:04

to be more specific:

$ tree 
├── deps.edn
├── Makefile
└── src
    └── react_deployment
        ├── config.clj
        └── core.clj

Lone Ranger13:09:39

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 yes.

Lone Ranger13:09:44

yep that did it

Lone Ranger13:09:53

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 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


(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 or maybe create a pod around the Python AWS SDK.


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

👍 6

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 ;-)

Michael W23:09:40

Have you guys seen this? I am using it for some minor stuff but it's got the entire set of services for AWS.