I'm trying to reach out to the terminal in Clojure to concatenate two binary files together.
So I'm trying to do something like: cat file1 file2 > target
I've started looking at conch but I can't seem to get cat
to treat my inputs as file paths rather than strings, e.g.
(def files '["/tmp/file1" "/tmp/file2"])
(defn add-to-target [files target]
(cat {:in files :out (java.io.File. target)}))
(add-to-target files "/tmp/target")
The result written to the /tmp/target
file is:
/tmp/file1
/tmp/file2
I'm happy to try other (perhaps more Clojure idiomatic) ways to do this.
Thanks in advance.
Here you go:
(ns user
(:require [clojure.java.io :as io]))
(defn catto [f1 f2 out]
(with-open [o (io/output-stream out)]
(io/copy (io/file f1) o)
(io/copy (io/file f2) o)))
;; in REPL
;; > (catto "station.mov" "super.pdf" "zzz.bin")
Take a look at clojure.java.io docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With