Skip to content

Instantly share code, notes, and snippets.

@gerritjvv
Last active July 19, 2024 13:29
Show Gist options
  • Save gerritjvv/5866665 to your computer and use it in GitHub Desktop.
Save gerritjvv/5866665 to your computer and use it in GitHub Desktop.
Calling an external process from Clojure
(comment
This is the easiest and most concise way of calling an external process in Java. The inheritIO methods causes the command to output stdout and errout to the same place as your current process (which most of the times is the console), no need to create mechanisms for reading asynchronously from input streams to get at the information.
http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html
)
(def ret (.waitFor (-> (ProcessBuilder. ["gzip" "-t" "g.txt.gz"]) .inheritIO .start)))
@algal
Copy link

algal commented Mar 17, 2016

This is gold. Thanks for posting it.

@optevo
Copy link

optevo commented Jan 5, 2018

Ditto - just what I was looking for.

@GlennS
Copy link

GlennS commented Jan 17, 2018

@enaeher
Copy link

enaeher commented Dec 12, 2019

@GlennS clojure.java.shell/sh does not solve the same problem this does, because it does not redirect IO to the subprocess.

@gerritjvv--thank you, this is exactly what I needed.

@enesj
Copy link

enesj commented May 24, 2022

Thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment