planck

Planck ClojureScript REPL
gowder 2017-01-05T00:22:20.000124Z

Hey @mfikes --- do you have a moment to be bugged with a planck question? Or any other wise people in the room 🙂... Does planck.shell/sh support piping? I'm trying to achieve the equivalent of echo "#foo\nbar" | pandoc -o fbb.html in shell (which just generates a html file from a markdown string). Tried the following, which just silently fails:

#!/usr/bin/env planck
(ns panpdf.core
  (:require [planck.shell :refer [sh]]))
(def s "#foo\nbar")
(sh "echo" s "|" "pandoc" "-o" "fbb.html")
looking at the return, I seem to be getting:
{:exit 0, :out #foo
bar | pandoc -o fbb.html
, :err }

gowder 2017-01-05T00:24:29.000125Z

also tried it with some extra escaped quotes around the string, i.e., (def s "\"#foo\nbar\"") -- still no dice

mfikes 2017-01-05T00:26:03.000126Z

Well, piping is an aspect of a shell itself. The sh function just launches an executable with arguments. I suspect the same would also fail with clojure.java.shell/sh

gowder 2017-01-05T00:26:22.000127Z

ooooooh

gowder 2017-01-05T00:26:31.000128Z

that makes sense...

gowder 2017-01-05T00:27:57.000129Z

I guess there's no avoiding shell scripts here then. oh well! thanks 🙂

mfikes 2017-01-05T00:28:38.000130Z

The only thing I can think to try would be to spit the string to a temp file and then have pandoc operate on the file

gowder 2017-01-05T00:28:59.000131Z

which might be worth it. Oh hey, another great use for UUIDs!

gowder 2017-01-05T00:29:41.000132Z

muchos gracias!

mfikes 2017-01-05T00:32:09.000133Z

It might be possible to launch bash and tell it to pipe via some -e construct. Hrm

gowder 2017-01-05T00:33:19.000134Z

iinteresting.

gowder 2017-01-05T00:33:38.000135Z

bash -c seems to execute from a string...

gowder 2017-01-05T00:35:38.000136Z

huzzah!

mfikes 2017-01-05T00:35:46.000137Z

Ahh yeah. Then maybe the string can construct a pipe

🤘 1
gowder 2017-01-05T00:36:06.000138Z

#!/usr/bin/env planck
(ns panpdf.core
  (:require [planck.shell :refer [sh]]))
(def s "\"#foo\nbar\"")
(sh "bash" "-c" (str "echo " s " | pandoc -o fbb.html"))
works! bam!

gowder 2017-01-05T00:38:05.000139Z

that's awesome

mfikes 2017-01-05T00:38:32.000140Z

Cool!

gowder 2017-01-05T00:39:49.000141Z

and now I don't have to write any shell or any haskell to manipulate text before sending it to pandoc. bwahahahaha

slipset 2017-01-05T09:44:24.000142Z

you can do this even simpler

slipset 2017-01-05T09:44:48.000143Z

sh accepts a :in argument

slipset 2017-01-05T09:45:55.000147Z

line 27 of that gist.

slipset 2017-01-05T09:47:04.000148Z

which would translate into something like

slipset 2017-01-05T09:47:11.000149Z

#!/usr/bin/env planck
(ns panpdf.core
  (:require [planck.shell :refer [sh]]))
(def s "\"#foo\nbar\"")
(sh "pandoc -o fbb.html" :in s)

slipset 2017-01-05T09:47:18.000150Z

from the example above.

👍 2
gowder 2017-01-05T16:10:42.000155Z

ooooooh good catch, thanks @slipset