Skip to content

Instantly share code, notes, and snippets.

@borkdude
Created May 13, 2017 14:02
Show Gist options
  • Save borkdude/07b97a3d7fb9183598b7b2a940e35407 to your computer and use it in GitHub Desktop.
Save borkdude/07b97a3d7fb9183598b7b2a940e35407 to your computer and use it in GitHub Desktop.
Standard input with lumo / node / ClojureScript
#!/usr/bin/env lumo
(defn greeting! [name]
(println (str "Hello " name "!")))
(def stdinput (atom ""))
(js/require "process")
(.setEncoding js/process.stdin "utf8")
(.on js/process.stdin "data"
(fn [data]
(swap! stdinput #(str % data))))
(.on js/process.stdin "end"
(fn []
(swap! stdinput (fn [s]
(subs s 0 (dec (count s)))))
(greeting! @stdinput)))
;; echo foo | ./script.cljs -> "Hello foo!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment