This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-12
Channels
- # bangalore-clj (4)
- # beginners (40)
- # boot (53)
- # cider (34)
- # cljs-dev (9)
- # cljsrn (11)
- # clojure (113)
- # clojure-boston (5)
- # clojure-dev (9)
- # clojure-dusseldorf (4)
- # clojure-russia (8)
- # clojure-spec (11)
- # clojure-uk (12)
- # clojurescript (88)
- # cloverage (17)
- # conf-proposals (4)
- # core-async (30)
- # cursive (9)
- # datomic (107)
- # euroclojure (5)
- # hoplon (196)
- # luminus (10)
- # off-topic (20)
- # om (24)
- # om-next (1)
- # onyx (80)
- # parinfer (3)
- # pedestal (16)
- # planck (44)
- # proton (8)
- # protorepl (1)
- # re-frame (19)
- # reagent (7)
- # spacemacs (2)
- # untangled (29)
- # yada (25)
Hey, I'm trying to run shell commands from planck, but can't get it to work. I'm using a fish shell, if that matters.
planck
(require '[planck.shell :as shell])
(shell/sh "pwd") => {.. :out "currentfolder/" ..}
(shell/sh "ls") => {:out "some/ folders/"}
(shell/sh "cd some") => launch path not accessible
(shell/sh "cd" "some") => {:exit 0 :out "" :err ""}
(shell/sh "pwd") => {.. :out "currentfolder/" ..}
@kauko: Glad to help: Planck is designed to behave like clojure.java.shell
, which pretty much matches what you show above. If you’d like to execute a command in some other directory, you can
(shell/with-sh-dir “some"
(shell/sh "pwd”))
(You’ll need to (require-macros '[planck.shell :as shell])
)Oh, what I meant is, the (shell/sh "cd" "some")
does not seem to actually change the directory in which I am
Try running (shell/sh “echo” “$$”)
a couple times and see if it gives you the same process ID
Just wondering if it’s doing the cd
in a sub-process instead of changing the directory in the process you’re running from
(shell/with-sh-dir my-folder (shell/sh "for" "i" "in ".svg*;" "pwd"))
gives "launch path not accessible".
Yes, I believe (shell/sh "cd" "some”)
changes directory, but it is like a “tree falling in a forest."
I don't know if this is related to the java.shell thing you mentioned, I don't really know what that means tbh 😄
I think you need to put your fish shell commands into an executable script and then use shell/sh
to execute the script
(shell/sh "cd" "some”)
changes directory, but there is nothing executed in that directory afterwards in order to make use of its side effect
Ugh, it's not working. There's so many places where this can go wrong, and I'm getting so little feedback (it's not planck's fault entirely, I don't have much experience with scripting fish)
Maybe you could leave fish out of the loop entirely and just write the whole script in planck/cljs?
@manutter51: Actually, that’s a compelling idea 🙂
I’ve done it some, it’s really fun
I’ve been looking for a good command-line clj tool ever since jark faded into obscurity, planck is awesome
For example, you can use planck.core/file-seq
and then use Clojure sequence abstractions (even with doseq
for example), to easily cobble together scripts.
@kauko: I’ve confirmed Planck can run executable scripts written using Fish. For example myscript
containing
#!/usr/local/bin/fish
pwd
works
cljs.user=> (shell/sh "myscript")
{:exit 0, :out "/Users/mfikes/Desktop\n", :err “"}
I wrote a script that scans through JBoss log files and prints out the stack traces of exceptions, based on the observation that the stack traces are all indented
Yeah, that's what I probably should do (do everything with planck), but this is a script I'll have run very rarely, and honestly I've spent way too much time with this already 😄
I realised that when I use the macro to run a command in another folder, the script doesn't exist in THAT folder
@kauko: Right. Absolute path works. (And FWIW, that behavior is consistent with clojure.java.shell
.)
Hmm, I think I got to work with the absolute path. Any way I can print the output though? I guess it's not printing because of the with-dir macro?
The output of your Fish script should be included in :out
and :err
of the return value of planck.shell/sh
.
This is a script that generates .png files from .svg files, so it runs for a pretty long time per folder.