Skip to content

Instantly share code, notes, and snippets.

@gerritjvv
Last active May 24, 2022 21:46
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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