This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-23
Channels
- # adventofcode (13)
- # announcements (7)
- # atom-editor (2)
- # babashka (6)
- # beginners (77)
- # biff (2)
- # calva (14)
- # cider (25)
- # circleci (2)
- # clj-on-windows (39)
- # clojars (1)
- # clojure (36)
- # clojure-belgium (4)
- # clojure-europe (78)
- # clojure-norway (25)
- # clojure-spec (1)
- # clojurescript (11)
- # clr (1)
- # cursive (1)
- # datahike (43)
- # datomic (6)
- # dev-tooling (3)
- # emacs (5)
- # exercism (1)
- # jobs (1)
- # jobs-discuss (3)
- # kaocha (2)
- # lsp (32)
- # malli (4)
- # music (1)
- # off-topic (14)
- # pathom (4)
- # reitit (14)
- # shadow-cljs (5)
- # tools-deps (3)
- # vim (1)
- # xtdb (5)
Hey folks! I had a quick question about about epiccastle/bbssh
pod if anyone is familiar. I'm using this library to execute a long running process on a remote host with ffmpeg. By default, and in all the example docs you can execute a remote command and have the output sent back to your local machine, but as a future which will block derefing until the command exits. Since it's a command I anticipate taking over an hour, I'm hoping to stream the ffmpeg output continuously. Is there a simple way to do this? I'm getting close with using a :stream
output and transforming the input stream manually but I just wanted to double check and make sure there wasn't a much simpler method that I am missing...
Here is what I have working but takes a long time to show results:
(let [session (bbssh/ssh "remote_host"
{:username "ubuntu"
:port 22
:identity "~/my_ssh_key"})]
(-> (bbssh/exec session "ffmpeg -convert super long video" {:out :string})
deref
:out))
and here is the solution I'm moving towards:
(let [session (bbssh/ssh "remote_host"
{:username "ubuntu"
:port 22
:identity "~/my_ssh_key"})]
(let [command (bbssh/exec session "ffmpeg -convert super long video" {:out :stream})]
;; (println (char(.read (:out command))) returns immediately here, but not print...
;; I was going to try to run some kind of long reduce to repeatly grab chars and
;; println them with every readline
))
actually I ended up getting it working using this... not sure if it's the most elegant solution but works ok so far
(let [session (bbssh/ssh "remote_host"
{:username "ubuntu"
:port 22
:identity "~/my_ssh_key"})]
(let [command (bbssh/exec session "ffmpeg -convert super long video" {:out :stream})
line (atom "")]
(loop [c (.read (:out command))]
(when (not= c -1)
(if (= \newline (char c))
(do
(println @line)
(reset! line ""))
(swap! line #(str % (char c))))
(recur (.read (:out command)))))))
yeah this works. you can also use (with-open [stream (io/reader (:out command))] .. do something with .. (line-seq stream))
I just had an idea: A site like https://explainshell.com/explain?cmd=rm+-rf but with links / pointers to the relevant babashka functions / recipes. I probably won't have time to run this myself, but if anyone wants to pick this up as a project, feel free