This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-06
Channels
- # announcements (2)
- # babashka (22)
- # beginners (93)
- # calva (12)
- # cider (65)
- # clj-kondo (15)
- # cljdoc (5)
- # cljs-dev (4)
- # cljsrn (4)
- # clojure (65)
- # clojure-europe (2)
- # clojure-italy (1)
- # clojure-nl (1)
- # clojure-norway (1)
- # clojure-spec (40)
- # clojure-uk (7)
- # clojurescript (12)
- # conjure (1)
- # cursive (2)
- # data-science (13)
- # datomic (1)
- # dirac (12)
- # emacs (3)
- # figwheel-main (19)
- # ghostwheel (5)
- # helix (6)
- # kaocha (1)
- # leiningen (6)
- # news-and-articles (2)
- # off-topic (17)
- # pathom (5)
- # re-frame (59)
- # reitit (17)
- # restql (1)
- # shadow-cljs (31)
- # spacemacs (5)
- # spire (3)
- # sql (35)
Hi, guys! I'm starting to play with Babashka and I was trying to do a script similar to kubectl edit deployment <deployment-name>
. It spawns a vi for editing, and after the user saves it, it do some stuff with the saved file. I tried doing the following:
(->
(ProcessBuilder. [ "vi" temp-file-name])
(.redirectOutput ProcessBuilder$Redirect/INHERIT)
(.redirectInput ProcessBuilder$Redirect/INHERIT)
(.redirectError ProcessBuilder$Redirect/INHERIT)
(.start))
following the recommendation of this https://stackoverflow.com/questions/9690702/how-can-i-launch-vi-from-within-java-under-commons-exec.
But it opens VI but it does not seem to have the normal capabilities such as visual mode, insert mode, and the possibility of editing the file. Does any one have ever tried something similar?That's a pretty interesting use case. When I try this:
(import 'java.lang.ProcessBuilder$Redirect)
(->
(ProcessBuilder. [ "vi" "README.md"])
(.redirectOutput ProcessBuilder$Redirect/INHERIT)
(.redirectInput ProcessBuilder$Redirect/INHERIT)
(.redirectError ProcessBuilder$Redirect/INHERIT)
(.start))
I am able to edit a file and leave vi againbtw you can also use .inheritIO
:
(->
(ProcessBuilder. [ "nano" "README.md"])
(.inheritIO)
(.start))
Cool! Didn't know about the .inheritIO.
I'm using iterm on a mac. Let me try another terminal.
Leaving nano also has troubles for me in iterm and http://terminal.app
just running the process builder works for me. So I guess it is a problem with the code that calls my subcommand. I'm using docopt, so it is probably related with that.
thanks for the help!
There's also some info here: https://stackoverflow.com/a/10341642/6264
If you figure this out, please leave a note in an issue, so we can document it somewhere
so, I found the problem I was having. I'm building a CLI
and my subcommands are being executed async by wrapping them in an async block, which redirecting the substreams. Once I replaced it by another ProcessBuilder with an .inheritIO
it worked as expected. So I must differentiate better which commands a want to run in this async block and which one would run in a "normal" ProcessBuilder.
Regarding this, what would like me to document on an issue?
Maybe you can post your script in a gist, so I could try if this also works on my machine - and then I can decide which parts would be interesting to document. E.g. I wrote already a part about Process here: https://book.babashka.org/#_java_lang_processbuilder
Cool! I'll do that and send it here.
Thanks for the help!
The gist with the code. https://gist.github.com/felipegmarques/f8a7a2555293c4b403e53be94116c569
cool! you're welcome! And thanks for the amazing tool. Started using it yesterday and I'm really enjoying it.