diff --git a/README.md b/README.md index 214171e..4cc6fd7 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ This is particularly handy when you want to supply commands coming from the comm (apply shell "ls -la" *command-line-args*) ``` -The `shell` function checks the exit code and throws if it is non-zero: +The `shell` function checks the command's exit code and throws if it is non-zero: ``` clojure user=> (shell "ls nothing") @@ -96,8 +96,8 @@ ls: nothing: No such file or directory Execution error (ExceptionInfo) at babashka.process/check (process.cljc:113). ``` -To avoid throwing, you can use `:continue true`. You will still see the error -being printed to stderr, but no exception will be thrown. That is convenient +To avoid throwing when the command's exit code is non-zero, use `:continue true`. +You will still see the error printed to stderr, but no exception will be thrown. This is convenient when you want to handle the `:exit` code yourself: ``` clojure @@ -106,6 +106,9 @@ ls: nothing: No such file or directory 1 ``` +> Note that `:continue true` only suppresses throwing an exception when the executed command's exit code is non-zero. +> Other exceptions can throw, for example, when the executable is not found. + To collect output as a `:string`, use the `:out :string` option as the first argument: ``` clojure diff --git a/src/babashka/process.cljc b/src/babashka/process.cljc index 83e5f65..4ec43a6 100644 --- a/src/babashka/process.cljc +++ b/src/babashka/process.cljc @@ -638,7 +638,7 @@ (defn shell "Convenience function around `process` that was originally in `babashka.tasks`. Defaults to inheriting I/O: input is read and output is printed - while the process runs. Throws on non-zero exit codes. Kills all + while the process runs. Defaults to throwing on non-zero exit codes. Kills all subprocesses on shutdown. Optional options map can be passed as the first argument, followed by multiple command line arguments. The first command line argument is automatically tokenized. Counter to @@ -646,6 +646,10 @@ new (bash, etc.) shell, it just shells out to a program. As such, it does not support bash syntax like `ls *.clj`. + Supported options: + - `:continue`: if `true`, suppresses throwing on non-zero process exit code. + - see `process` for other options + Examples: - `(shell \"ls -la\")` ;; `\"ls -la\"` is tokenized as `[\"ls\" \"-la\"]`