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
is it not meant to do that?
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
oh
hmm
Alright, my previous question was mostly me trying to figure planck out
but what I'm actually trying to do, is run a fish script in the shell
from planck
(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 😄
For your for
example: for
is not a program, right?
I think you need to put your fish shell commands into an executable script and then use shell/sh
to execute the script
It's a fish command
(shell/sh "cd" "some”)
changes directory, but there is nothing executed in that directory afterwards in order to make use of its side effect
manutter51, I'll try that 🙂
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?
Do you have a working Fish script? (Meaning can you run it outside of Planck?)
@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 😄
@mfikes: awesome, thanks!
I realised that when I use the macro to run a command in another folder, the script doesn't exist in THAT folder
I guess I'll have to get an absolute path to the script
@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
.
Hmm, but if the script I'm running has a for loop with an echo
I won't get the :out before the script finishes, right?
Right.
Oh, well, that doesn't really help me that much 🙂
This is a script that generates .png files from .svg files, so it runs for a pretty long time per folder.
But for only 3 folders
Thanks a bunch for planck btw. We've used it for a couple of things now 🙂 One of my team mates made a planck script for bitbar, that shows our open pull requests from github
Yeah, if you want to execute a command on all of the *.svg
files in a folder, and indicate output as things proceed, you can use Planck to do that. (I actually did something like that recently using Image Magick.