(defn ssh-exec
"Run a command via ssh-exec."
[#^Session session #^String cmd in out opts]
(let [#^ChannelExec exec (open-channel session :exec)
out-stream (java.io.ByteArrayOutputStream.)
err-stream (java.io.ByteArrayOutputStream.)]
(doto exec
(.setInputStream
(if (string? in)
(java.io.ByteArrayInputStream. (.getBytes #^String in))
in)
false)
(.setOutputStream out-stream)
(.setErrStream err-stream)
(.setCommand cmd))
(when (contains? opts :pty)
(call-method
com.jcraft.jsch.ChannelSession 'setPty [Boolean/TYPE]
exec (boolean (opts :pty))))
(with-connection exec
(while (connected? exec)
(Thread/sleep 100))
[(.getExitStatus exec)
(if (= :bytes out)
(.toByteArray out-stream)
(.toString out-stream out))
(if (= :bytes out)
(.toByteArray err-stream)
(.toString err-stream out))])))
Used in 0 other vars
Comments top
No comments for ssh-exec. Log in to add a comment.