Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #112: pre-start-fn in exec #118

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
[Babashka process](https://github.com/babashka/process)
Clojure library for shelling out / spawning sub-processes

## Unreleased

- Fix [#112](https://github.com/babashka/process/issues/112): pre-start-fn in exec

## 0.4.16

- [#100](https://github.com/babashka/process/issues/100): preserve single-quotes in double-quoted string
Expand Down
18 changes: 13 additions & 5 deletions src/babashka/process.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,9 @@
{:arglists '([opts? & args])}
[& args]
(let [{:keys [cmd opts]} (parse-args args)]
(let [{:keys [escape env extra-env]
:or {escape default-escape}
(let [{:keys [escape env extra-env pre-start-fn]
:or {escape (:escape *defaults*)
pre-start-fn (:pre-start-fn *defaults*)}
:as opts} opts
cmd (if (and (string? cmd)
(not (.exists (io/file cmd))))
Expand All @@ -585,9 +586,13 @@
cmd (mapv str-fn cmd)
arg0 (or (:arg0 opts)
(first cmd))
cmd (let [program-resolver (:program-resolver opts -program-resolver)
[program & args] cmd]
program-resolver (or (:program-resolver opts)
(:program-resolver *defaults*))
cmd (let [[program & args] cmd]
(into [(program-resolver program)] args))
_ (when pre-start-fn
(let [interceptor-map {:cmd cmd}]
(pre-start-fn interceptor-map)))
[program & args] cmd
args (cons arg0 args)
^java.util.Map env (into (or env (into {} (System/getenv))) extra-env)]
Expand All @@ -609,7 +614,10 @@
while the process runs. Throws 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.
first command line argument is automatically tokenized. Counter to
what the name of this function may suggest, it does not start a
new (bash, etc.) shell, it just shells out to a program. As such, it
does not support bash syntax like `ls *.clj`.

Examples:

Expand Down