Back

exec (clj)

(source)

function

(exec & opts+args)
Execute a command and on successful exit, return the captured output, else throw RuntimeException. Args are the same as 'start' and options if supplied override the default 'exec' settings.

Examples

clojure
(ns clojure.test-clojure.java.process
  (:require
    [clojure.test :refer :all]
    [clojure.java.process :as p]
    [clojure.string :as str]))

(deftest test-stderr-redirect
  ;; capture to stdout and return string
  (is (not (str/blank? (p/exec "bash" "-c" "ls"))))

  ;; print to stderr, capture nil
  (is (nil? (p/exec "bash" "-c" "ls >&2")))

  ;; redirect, then capture to string
  (is (not (str/blank? (p/exec {:err :stdout} "bash" "-c" "ls >&2")))))
clojure/clojure
(ns clojure.test-clojure.java.process
  (:require
    [clojure.test :refer :all]
    [clojure.java.process :as p]
    [clojure.string :as str]))

(deftest test-stderr-redirect
  ;; capture to stdout and return string
  (is (not (str/blank? (p/exec "bash" "-c" "ls"))))

  ;; print to stderr, capture nil
  (is (nil? (p/exec "bash" "-c" "ls >&2")))

  ;; redirect, then capture to string
  (is (not (str/blank? (p/exec {:err :stdout} "bash" "-c" "ls >&2")))))