Namespaces

 
0.2.0-SNAPSHOT Arrow_down_16x16

ssh-exec

clj-ssh.ssh

  • (ssh-exec session cmd in out opts)
Run a command via ssh-exec.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clj_ssh/ssh.clj:338 top

(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))])))
Vars in clj-ssh.ssh/ssh-exec: with-connection boolean contains? defn doto let string? when while
Used in 0 other vars

Comments top

No comments for ssh-exec. Log in to add a comment.