-
When any of the This at first sight might cause confusion to clojurians, because they are accustomed to think at the clojure context and thus their first expectation is for the clojure streams to be inherited. It can also cause some confusing at first puzzling effects, such as the error output of a failing Was this redirection at the java level a design decision or rather happened for convenience, or maybe both? I'm trying to ascertain whether it would be a more convenient option to inherit from the clojure streams by default or add an additional option for this or just update the documentation to elaborate just a bit more on the inheritance so that clojurians are less likely to be confused by the side effects. What do you think? :) Looking at the code, the redirection to the java process happens in the process/src/babashka/process.cljc Line 221 in bd203b7 (defn- build
(^java.lang.ProcessBuilder [cmd] (build cmd nil))
(^java.lang.ProcessBuilder [^java.util.List cmd opts]
(let [
;; ...
pb (cond-> (java.lang.ProcessBuilder. ^java.util.List cmd)
dir (.directory (io/file dir))
env (set-env env)
extra-env (add-env extra-env))]
(case out
:inherit (.redirectOutput pb ProcessBuilder$Redirect/INHERIT)
:write (.redirectOutput pb (ProcessBuilder$Redirect/to (io/file out-file)))
:append (.redirectOutput pb (ProcessBuilder$Redirect/appendTo (io/file out-file)))
nil)
(case err
:inherit (.redirectError pb ProcessBuilder$Redirect/INHERIT)
:write (.redirectError pb (ProcessBuilder$Redirect/to (io/file err-file)))
:append (.redirectError pb (ProcessBuilder$Redirect/appendTo (io/file err-file)))
nil)
(case in
:inherit (.redirectInput pb ProcessBuilder$Redirect/INHERIT)
nil)
pb))) To reproduce the Hudini effect with
clojure.lang.ExceptionInfo:
{:type :sci/error, :line 1, :column 1, :message "",
#...
}
at sci.impl.utils$rethrow_with_location_of_node.invokeStatic (utils.cljc:128)
#...
Caused by: clojure.lang.ExceptionInfo:
{:proc #object[java.lang.ProcessImpl 0x1d310663 "Process[pid=28332, exitValue=2]"], :exit 2
# ...
clojure.lang.ExceptionInfo: ls: unknown option -- ---
Try '/usr/bin/ls --help' for more information.
;; ...
{:type :sci/error, :line 1, :column 1,
Caused by: clojure.lang.ExceptionInfo: ls: unknown option -- ---
Try '/usr/bin/ls --help' for more information.
{:proc #object[java.lang.ProcessImpl 0x3b4ce6c0 "Process[pid=22280, exitValue=2]"],
;; ... Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can write to (process [...] {:out *out* :err *err*}) This is not the default because there is buffering overhead when you write to those. The defaults are chosen like they are now so you can compose $ bb -e "(require '[babashka.process :refer [process]]) (-> (process \"ls\") (process \"cat\" {:out :string}) deref :out)" There are always trade-offs and no one default will make everybody happy. |
Beta Was this translation helpful? Give feedback.
You can write to
*out*
and*err*
using:This is not the default because there is buffering overhead when you write to those.
The defaults are chosen like they are now so you can compose
process
:$ bb -e "(require '[babashka.process :refer [process]]) (-> (process \"ls\") (process \"cat\" {:out :string}) deref :out)"
There are always trade-offs and no one default will make everybody happy.