|
219 | 219 | :escape default-escape |
220 | 220 | :program-resolver default-program-resolver}) |
221 | 221 |
|
222 | | -(defn- normalize-opts [{:keys [:out :err :in :inherit] :as opts}] |
| 222 | +(def ^java.io.File null-file |
| 223 | + (delay (io/file (if windows? |
| 224 | + "NUL" |
| 225 | + "/dev/null")))) |
| 226 | + |
| 227 | +(defn- normalize-opts [{:keys [out err in inherit] :as opts}] |
223 | 228 | (cond-> opts |
224 | 229 | (and inherit (not out)) |
225 | 230 | (-> (assoc :out :inherit)) |
|
265 | 270 | :inherit (.redirectOutput pb ProcessBuilder$Redirect/INHERIT) |
266 | 271 | :write (.redirectOutput pb (ProcessBuilder$Redirect/to (io/file (str out-file)))) |
267 | 272 | :append (.redirectOutput pb (ProcessBuilder$Redirect/appendTo (io/file (str out-file)))) |
268 | | - nil) |
| 273 | + :discard (.redirectOutput pb (if-before-jdk8 |
| 274 | + (ProcessBuilder$Redirect/to @null-file) |
| 275 | + ProcessBuilder$Redirect/DISCARD)) |
| 276 | + (when (instance? java.lang.ProcessBuilder$Redirect out) |
| 277 | + (.redirectOutput pb out))) |
269 | 278 | (case err |
270 | 279 | :out (.redirectErrorStream pb true) |
271 | 280 | :inherit (.redirectError pb ProcessBuilder$Redirect/INHERIT) |
272 | 281 | :write (.redirectError pb (ProcessBuilder$Redirect/to (io/file (str err-file)))) |
273 | 282 | :append (.redirectError pb (ProcessBuilder$Redirect/appendTo (io/file (str err-file)))) |
274 | | - nil) |
| 283 | + :discard (.redirectError pb (if-before-jdk8 |
| 284 | + (ProcessBuilder$Redirect/to @null-file) |
| 285 | + ProcessBuilder$Redirect/DISCARD)) |
| 286 | + (when (instance? java.lang.ProcessBuilder$Redirect err) |
| 287 | + (.redirectError pb err))) |
275 | 288 | (case in |
276 | 289 | :inherit (.redirectInput pb ProcessBuilder$Redirect/INHERIT) |
277 | 290 | (when (or (instance? java.io.File in) |
|
385 | 398 | stderr (.getErrorStream proc) |
386 | 399 | out (if (and out (or (identical? :string out) |
387 | 400 | (identical? :bytes out) |
388 | | - (not (keyword? out)))) |
| 401 | + (and (not (keyword? out)) |
| 402 | + (not (instance? java.lang.ProcessBuilder$Redirect out))))) |
389 | 403 | (future (copy stdout out out-enc)) |
390 | 404 | stdout) |
391 | 405 | err (if (and err (or (identical? :string err) |
392 | 406 | (identical? :bytes err) |
393 | | - (not (keyword? err)))) |
| 407 | + (and (not (keyword? err)) |
| 408 | + (not (instance? java.lang.ProcessBuilder$Redirect err))))) |
394 | 409 | (future (copy stderr err err-enc)) |
395 | 410 | stderr)] |
396 | 411 | ;; wrap in futures, see https://github.com/clojure/clojure/commit/7def88afe28221ad78f8d045ddbd87b5230cb03e |
|
470 | 485 | For writing output to a file, you can set `:out` and `:err` to a `java.io.File` object, or a keyword: |
471 | 486 | - `:write` + an additional `:out-file`/`:err-file` + file to write to the file. |
472 | 487 | - `:append` + an additional `:out-file`/`:err-file` + file to append to the file. |
| 488 | + To discard `:out` or `:err`, use `:discard` |
473 | 489 | - `:prev`: output from `:prev` will be piped to the input of this process. Overrides `:in`. |
474 | 490 | - `:inherit`: if true, sets `:in`, `:out` and `:err` to `:inherit`. |
475 | 491 | - `:dir`: working directory. |
|
0 commit comments