This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-12
Channels
- # adventofcode (6)
- # announcements (10)
- # beginners (70)
- # boot (55)
- # calva (15)
- # cljs-dev (18)
- # clojure (32)
- # clojure-europe (4)
- # clojure-nl (2)
- # clojure-spec (20)
- # clojure-uk (6)
- # clojurescript (14)
- # cursive (11)
- # datomic (31)
- # figwheel-main (7)
- # fulcro (1)
- # incanter (1)
- # jobs-discuss (3)
- # juxt (1)
- # off-topic (17)
- # onyx (5)
- # pathom (3)
- # pedestal (2)
- # quil (20)
- # re-frame (6)
- # reitit (1)
- # ring (2)
- # rum (5)
- # shadow-cljs (73)
- # spacemacs (5)
- # tools-deps (11)
- # uncomplicate (1)
- # unrepl (1)
- # yada (11)
i've got a pretty lengthy bash command i'd like to execute in clojure. Is there any way i can just execute the full command with all its arguments as a single string?
sure, via (clojure.java.shell/sh "/bin/bash" "-c" cmd)
for example
you can do a similar trick with ProcessBuilder if you need more flexibility about how the command runs
shell/sh itself doesn't invoke the OS shell - for one thing that's not portable
ins)user=> (.start (ProcessBuilder. (into-array ["/bin/bash" "-c" "ls"])))
#object[java.lang.UNIXProcess 0x2a8d39c4 "java.lang.UNIXProcess@2a8d39c4"]
(ins)user=> (slurp (.getInputStream *1))
"CHANGELOG.md\nDockerfile\nREADME.md\nTAGS\nbin\ndashboards\ndeploy\ndev-resources\ndoc\ndoc-updates.otl\ndocker\ndocker-compose.yml\neastwood-config.clj\nprofiles.clj\nproject.clj\nresources\nsrc\ntarget\ntest\n"
(ins)user=> (require 'clojure.java.shell)
nil
(ins)user=> (clojure.java.shell/sh "/bin/bash" "-c" "ls")
{:exit 0, :out "CHANGELOG.md\nDockerfile\nREADME.md\nTAGS\nbin\ndashboards\ndeploy\ndev-resources\ndoc\ndoc-updates.otl\ndocker\ndocker-compose.yml\neastwood-config.clj\nprofiles.clj\nproject.clj\nresources\nsrc\ntarget\ntest\n", :err ""}
ok my issue is parsing out the arguments into an array like that. I tried using conch. And i'm trying to use ffmpeg. this command returns a non-zero exit code at the first step but also returns the info i want, but conch just hangs up at the first error
ffmpeg -i /Volumes/Video 1/DRUM_2018-12-19-15-00-54_597.mov 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,//
yeah, just use ProcessBuilder instead of conch
you need to explicitly call bash or sh to get things like |
those aren't execution features, they are shell features, so you need to start a shell
(so maybe conch is still OK for you, as long as you start a shell - I found ProcessBuilder much easier to use in anger)
haha... so like
(def output (.start (ProcessBuilder. (into-array ["/bin/bash" "-c" "ffmpeg -i /Volumes/Video 1/DRUM_2018-12-19-15-00-54_597.mov 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,//"]))))
yeah, but that's more than output - it is a Process
object that lets you read stdout, stderr, send to stdin, etc.
in my experience for interactive commands like ffmpeg if I want to send it input lines mid execution etc. Process directly instead of conch was easier
glad I could help
also, once you have an InputStream you are free to parse each line of input from the process with your own parser if sed and cut aren't "cutting it", so to speak
but if sed and cut work, no need to reinvent that
Anybody know how to use missing? with a reverse lookup? Is this supposed to work?
[(missing? $ ?l :account/_licenses)]
Also, is there a reason why I can't use 2 missing? statements in an or?
(or [(missing? $ ?a :account/licenses)] [(missing? $ ?a :account/email)])
(edited)
Error CompilerException java.lang.RuntimeException: Unable to resolve symbol: $ in this context
what is "missing?"
oh, if it's datomic the who vector should be quoted right?
There's more exposure here... but I will politely retreat back to #datomic if someone protests me posting here.
Something I discovered today is that YourKit works really well with Clojure in an IntelliJ setup (doesn’t interfere with Cursive).
For profiling Clojure code!
I was reading this earlier: http://yellerapp.com/posts/2014-05-21-tuning-clojure-an-experience-report.html
Figuring out what Java class names correspond to which parts of your Clojure code is kind of difficult though. But otherwise really helpful once you figure out what’s what.
What’s the best way to interop with Java methods that require a java.util.function? I know it can be done with reify but it is a bit verbose.