Why won't the following Clojure code tail a file via ssh?

Posted by Zubair on Stack Overflow See other posts from Stack Overflow or by Zubair
Published on 2011-01-06T19:50:23Z Indexed on 2011/01/06 19:53 UTC
Read the original article Hit count: 248

Filed under:

The following code never manages to tail a file. It simply hangs waiting for reader input. Has anyone tried anything similar?

(def output     (ref [] ))

(import 'ch.ethz.ssh2.Connection)
(import 'ch.ethz.ssh2.Session)
(import 'ch.ethz.ssh2.StreamGobbler)
(import 'java.lang.StringBuilder)
(import 'java.io.InputStream)
(import 'java.io.BufferedReader)
(import 'java.io.InputStreamReader)

(let [connection  (new Connection  "hostname")]
  (. connection connect)
  (let [ok         (. connection authenticateWithPassword "username"  "password" )
        session    (. connection openSession )]

    (. session execCommand "tail -f filename.txt")

    (let [sb      (StringBuilder.)
          stdout  (StreamGobbler. (. session getStdout))
          br      (BufferedReader. (InputStreamReader. stdout))
         ]

      (future (loop [line2 (. br readLine)] 
        (if (= line2 nil)  
          nil 
          (do 
            (dosync (ref-set output (conj @output line2)))
            (recur (. br readLine))))
          )
      )
    )
  )
)

© Stack Overflow or respective owner

Related posts about clojure