Back

capture (clj)

(source)

function

(capture input-stream & opts)
Read from input-stream until EOF and return a String (or nil if 0 length). Takes same opts as clojure.java.io/copy - :buffer-size and :encoding

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")))))