pipes
pipes copied to clipboard
some problems with quickstart example
Here's what I'm seeing when I run the quickstart example
(with-open [in (clojure.java.io/input-stream "README.md")
out (clojure.java.io/output-stream "line_count.txt")]
(->pipe->
in
[(exec ["grep" "java"])
(exec ["wc" "-l"])]
out))
;=> #pipes.job/job-ctl/reify--21836[{:status :pending, :val nil} 0x32e24e7f]
;; Exception in thread "Exec Default Executor" java.io.IOException: Stream Closed
;; at java.io.FileOutputStream.writeBytes(Native Method)
;; at java.io.FileOutputStream.write(FileOutputStream.java:326)
;; at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
;; at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
;; at java.io.FilterOutputStream.close(FilterOutputStream.java:158)
;; at clj_commons_exec.DefaultResultHandler.onProcessFailed(clj_commons_exec.clj:50)
;; at org.apache.commons.exec.DefaultExecutor$1.run(DefaultExecutor.java:205)
;; at java.lang.Thread.run(Thread.java:745)
(slurp "line_count.txt")
;=> ""
However, I'm able to run a variant of it with successful output and no error messages.
(def baos (java.io.ByteArrayOutputStream.))
;=> #'flowrweb.core/baos
(with-open [in (clojure.java.io/input-stream "README.md") out baos]
(->pipe->
in
[(exec ["cat" "README.md"])
(exec ["wc" "-l"])]
out))
;=> #pipes.job/job-ctl/reify--11259[{:status :pending, :val nil} 0x11bdd579]
(String. (.toByteArray baos) (. java.nio.charset.Charset defaultCharset))
;=> "157\n"
(.reset baos)
;=> nil