Skip to content
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
7 changes: 2 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ jobs:
deploy:
resource_class: large
docker:
- image: circleci/clojure:openjdk-8-lein
- image: circleci/clojure:openjdk-11-lein
working_directory: ~/repo
environment:
LEIN_ROOT: "true"
Expand All @@ -197,10 +197,7 @@ workflows:
matrix:
parameters:
os: [linux, macos, windows]
jdk: ['temurin@8','temurin@11','temurin@17','temurin@21']
exclude:
- os: macos
jdk: 'temurin@8'
jdk: ['temurin@11','temurin@17','temurin@21']
- test-native:
name: test-<< matrix.os >>-<< matrix.jdk>>
matrix:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ jobs:
strategy:
fail-fast: false
matrix:
java-version: ["8", "11", "17", "21"]
java-version: ["11", "17", "21"]
os: [ubuntu, macOS, windows]
exclude:
- java-version: "8"
os: macOS

runs-on: ${{ matrix.os }}-latest
name: test-${{ matrix.os }}-temurin@${{ matrix.java-version }}
Expand Down
48 changes: 29 additions & 19 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [`null-file`](#babashka.process/null-file)
- [`parse-args`](#babashka.process/parse-args) - Parses arguments to <code>process</code> to map with: * <code>:prev</code>: a (previous) process whose output is piped into the current process * <code>:cmd</code>: a vector of command line argument strings * <code>:opts</code>: options map Note that this function bridges the legacy <code>[cmds ?opts]</code> syntax to the newer recommended syntax <code>[?opts & args]</code> and therefore looks unnecessarily complex.
- [`pb`](#babashka.process/pb) - Returns a process builder (as record).
- [`pid`](#babashka.process/pid) - Returns the OS process id of <code>proc</code>, a process map returned by <code>process</code> or <code>process*</code>.
- [`pipeline`](#babashka.process/pipeline) - Returns the processes for one pipe created with -> or creates pipeline from multiple process builders.
- [`process`](#babashka.process/process) - Creates a child process.
- [`process*`](#babashka.process/process*) - Same as with <code>process</code> but called with parsed arguments (the result from <code>parse-args</code>).
Expand Down Expand Up @@ -39,7 +40,7 @@ Function.
Convenience macro around [`process`](#babashka.process/process). Takes command as varargs. Options can
be passed via metadata on the form or as a first map arg. Supports
interpolation via `~`
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L579-L609">Source</a></sub></p>
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L546-L576">Source</a></sub></p>

## <a name="babashka.process/*defaults*">`*defaults*`</a><a name="babashka.process/*defaults*"></a>

Expand All @@ -48,7 +49,7 @@ Convenience macro around [`process`](#babashka.process/process). Takes command a

Dynamic var containing overridable default options. Use
`alter-var-root` to change permanently or `binding` to change temporarily.
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L215-L220">Source</a></sub></p>
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L206-L211">Source</a></sub></p>

## <a name="babashka.process/alive?">`alive?`</a><a name="babashka.process/alive?"></a>
``` clojure
Expand All @@ -57,7 +58,7 @@ Dynamic var containing overridable default options. Use
```

Returns `true` if the process is still running and false otherwise.
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L710-L713">Source</a></sub></p>
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L677-L680">Source</a></sub></p>

## <a name="babashka.process/check">`check`</a><a name="babashka.process/check"></a>
``` clojure
Expand All @@ -76,17 +77,16 @@ Takes a process, waits until is finished and throws if exit code is non-zero.

Destroys the process and returns the input arg. Takes process or map
with :proc (`java.lang.ProcessBuilder`).
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L156-L161">Source</a></sub></p>
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L150-L155">Source</a></sub></p>

## <a name="babashka.process/destroy-tree">`destroy-tree`</a><a name="babashka.process/destroy-tree"></a>
``` clojure

(destroy-tree proc)
```

Same as [[`destroy`](#babashka.process/destroy)](#babashka.process/destroy) but also destroys all descendants. JDK9+
only. Falls back to [[`destroy`](#babashka.process/destroy)](#babashka.process/destroy) on older JVM versions.
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L165-L173">Source</a></sub></p>
Same as [`destroy`](#babashka.process/destroy) but also destroys all descendants.
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L157-L164">Source</a></sub></p>

## <a name="babashka.process/exec">`exec`</a><a name="babashka.process/exec"></a>
``` clojure
Expand All @@ -101,13 +101,13 @@ Replaces the current process image with the process image specified
Supported `opts`
- `:arg0`: override first argument (the executable). No-op on Windows.
- `:cmd`, `:env`,`:extra-env`, `:escape`,`:pre-start-fn` : see [`process`](#babashka.process/process).
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L634-L672">Source</a></sub></p>
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L601-L639">Source</a></sub></p>

## <a name="babashka.process/null-file">`null-file`</a><a name="babashka.process/null-file"></a>



<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L222-L225">Source</a></sub></p>
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L213-L216">Source</a></sub></p>

## <a name="babashka.process/parse-args">`parse-args`</a><a name="babashka.process/parse-args"></a>
``` clojure
Expand All @@ -124,7 +124,7 @@ Parses arguments to [`process`](#babashka.process/process) to map with:
Note that this function bridges the legacy `[cmds ?opts]` syntax to
the newer recommended syntax `[?opts & args]` and therefore looks
unnecessarily complex.
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L297-L346">Source</a></sub></p>
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L284-L333">Source</a></sub></p>

## <a name="babashka.process/pb">`pb`</a><a name="babashka.process/pb"></a>
``` clojure
Expand All @@ -133,7 +133,17 @@ Parses arguments to [`process`](#babashka.process/process) to map with:
```

Returns a process builder (as record).
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L348-L355">Source</a></sub></p>
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L335-L342">Source</a></sub></p>

## <a name="babashka.process/pid">`pid`</a><a name="babashka.process/pid"></a>
``` clojure

(pid proc)
```

Returns the OS process id of `proc`, a process map returned by
[`process`](#babashka.process/process) or [`process*`](#babashka.process/process*).
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L682-L686">Source</a></sub></p>

## <a name="babashka.process/pipeline">`pipeline`</a><a name="babashka.process/pipeline"></a>
``` clojure
Expand All @@ -147,11 +157,11 @@ Returns the processes for one pipe created with -> or creates

- When passing a process, returns a vector of processes of a pipeline created with `->` or [`pipeline`](#babashka.process/pipeline).
- When passing two or more process builders created with [`pb`](#babashka.process/pb): creates a
pipeline as a vector of processes (JDK9+ only).
pipeline as a vector of processes.

Also see [Pipelines](/README.md#pipelines).

<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L524-L558">Source</a></sub></p>
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L491-L525">Source</a></sub></p>

## <a name="babashka.process/process">`process`</a><a name="babashka.process/process"></a>
``` clojure
Expand Down Expand Up @@ -209,8 +219,8 @@ Creates a child process. Takes a command (vector of strings or
map. Typically used with [`destroy`](#babashka.process/destroy) or [`destroy-tree`](#babashka.process/destroy-tree) to ensure long
running processes are cleaned up on shutdown. The shutdown hook is
executed as soon as the child process ends.
- `:exit-fn`: a function which is executed upon exit. Receives process map as argument. Only supported in JDK11+.
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L453-L507">Source</a></sub></p>
- `:exit-fn`: a function which is executed upon exit. Receives process map as argument.
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L435-L489">Source</a></sub></p>

## <a name="babashka.process/process*">`process*`</a><a name="babashka.process/process*"></a>
``` clojure
Expand All @@ -219,7 +229,7 @@ Creates a child process. Takes a command (vector of strings or
```

Same as with [`process`](#babashka.process/process) but called with parsed arguments (the result from [`parse-args`](#babashka.process/parse-args))
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L367-L451">Source</a></sub></p>
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L354-L433">Source</a></sub></p>

## <a name="babashka.process/sh">`sh`</a><a name="babashka.process/sh"></a>
``` clojure
Expand All @@ -231,7 +241,7 @@ Convenience function similar to `clojure.java.shell/sh` that sets
`:out` and `:err` to `:string` by default and blocks. Similar to
`cjs/sh` it does not check the exit code (this can be done with
[`check`](#babashka.process/check)).
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L611-L621">Source</a></sub></p>
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L578-L588">Source</a></sub></p>

## <a name="babashka.process/shell">`shell`</a><a name="babashka.process/shell"></a>
``` clojure
Expand Down Expand Up @@ -259,7 +269,7 @@ Convenience function around [[`process`](#babashka.process/process)](#babashka.p
- `(shell {:out "/tmp/log.txt"} "git commit -m" "WIP")` ;; `"git commit -m"` is tokenized as `["git" "commit" "-m"]` and `"WIP"` is an additional argument

Also see the [`shell`](#babashka.process/shell) entry in the babashka book [here](https://book.babashka.org/#_shell).
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L680-L708">Source</a></sub></p>
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L647-L675">Source</a></sub></p>

## <a name="babashka.process/start">`start`</a><a name="babashka.process/start"></a>
``` clojure
Expand All @@ -268,7 +278,7 @@ Convenience function around [[`process`](#babashka.process/process)](#babashka.p
```

Takes a process builder, calls start and returns a process (as record).
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L560-L566">Source</a></sub></p>
<p><sub><a href="https://github.com/babashka/process/blob/master/src/babashka/process.cljc#L527-L533">Source</a></sub></p>

## <a name="babashka.process/tokenize">`tokenize`</a><a name="babashka.process/tokenize"></a>
``` clojure
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
[Babashka process](https://github.com/babashka/process)
Clojure library for shelling out / spawning sub-processes

## Unreleased

- [#188](https://github.com/babashka/process/issues/188): add `pid` ([@markokocic](https://github.com/markokocic))
- Drop JDK 8 support

## 0.6.25 (2025-12-21)

- Fix reflection warnings
Expand Down
26 changes: 0 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,32 +472,6 @@ The solution then it to use `pipeline` + `pb`:
(pb {:out :inherit} "grep" "5"))
```

The varargs arity of `pipeline` is only available in JDK9 or higher due to the
availability of `ProcessBuilder/startPipeline`. If you are on JDK8 or lower, the
following solution that reads the output of `tail` line by line may work for
you:

``` clojure
user=> (require '[clojure.java.io :as io])
nil

(def tail (process {:err :inherit} "tail" "-f" "log.txt"))

(def cat-and-grep
(-> (process {:err :inherit} "cat")
(process {:out :inherit
:err :inherit} "grep 5")))

(binding [*in* (io/reader (:out tail))
*out* (io/writer (:in cat-and-grep))]
(loop []
(when-let [x (read-line)]
(println x)
(recur))))
```

Another solution is to let bash handle the pipes by shelling out with `bash -c`.

## Program Resolution

### macOS & Linux
Expand Down
Loading
Loading