Fork me on GitHub
#planck
<
2017-01-05
>
gowder00:01:20

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 }

gowder00:01:29

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

mfikes00:01:03

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

gowder00:01:31

that makes sense...

gowder00:01:57

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

mfikes00:01:38

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

gowder00:01:59

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

gowder00:01:41

muchos gracias!

mfikes00:01:09

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

gowder00:01:19

iinteresting.

gowder00:01:38

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

mfikes00:01:46

Ahh yeah. Then maybe the string can construct a pipe

gowder00:01:06

#!/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!

gowder00:01:05

that's awesome

gowder00:01:49

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

slipset09:01:24

you can do this even simpler

slipset09:01:48

sh accepts a :in argument

slipset09:01:55

line 27 of that gist.

slipset09:01:04

which would translate into something like

slipset09:01:11

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

slipset09:01:18

from the example above.

gowder16:01:42

ooooooh good catch, thanks @slipset