Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by
edited by

clojure.java.shell/launch doesn't drain output which makes the process hang. Here is an example of curl downloading and printing 1mb of text:

 $ clj
Clojure 1.11.0-alpha4
user=> (require '[clojure.java.shell :refer [launch]])
nil
user=> (launch "curl" "https://gist.githubusercontent.com/khaykov/a6105154becce4c0530da38e723c2330/raw/41ab415ac41c93a198f7da5b47d604956157c5c3/gistfile1.txt")

I think a solution would be to move clojure.java.shell away from (.exit (Runtime/getRuntime)) for this specific function and use java.lang.ProcessBuilder instead, which has an option to discard output.

https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/ProcessBuilder.Redirect.html#DISCARD

One caveat: DISCARD is only available on Java 9 and newer. We could do resolve in a try/catch on the top level to see if DISCARD is available and then use that, if available and fall back on PIPE if it isn't. Alternatives: use a thread to consume output while the process is running. Or redirect to a temporary file.

I'll provide a patch, if desired, and when agreed upon the direction of the solution.

1 Answer

0 votes
by
selected by
 
Best answer
...