Skip to content
Open
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
6 changes: 6 additions & 0 deletions .changes/shell-process-group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-plugin-shell": minor:feat
"@tauri-apps/plugin-shell": minor:feat
---

Add `processGroup` option to spawn commands in a new process group (POSIX) or job object (Windows), allowing the entire process tree to be killed when calling `kill()` on the child process.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions plugins/shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ regex = "1"
open = { version = "5", features = ["shellexecute-on-windows"] }
encoding_rs = "0.8"
os_pipe = "1"
process-wrap = { version = "8.2", features = ["std"] }

[target.'cfg(unix)'.dependencies]
libc = "0.2"

[target.'cfg(target_os = "ios")'.dependencies]
tauri = { workspace = true, features = ["wry"] }
10 changes: 10 additions & 0 deletions plugins/shell/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ interface SpawnOptions {
* @since 2.0.0
* */
encoding?: string
/**
* When enabled, spawns the child process in its own process group (POSIX)
* or job object (Windows). This allows killing the entire process tree
* when calling `kill()` on the child process.
*
* Useful for programs that spawn child processes, such as PyInstaller wrappers.
*
* Defaults to `false`.
*/
processGroup?: boolean
}

/** @ignore */
Expand Down
7 changes: 7 additions & 0 deletions plugins/shell/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ pub struct CommandOptions {
env: Option<HashMap<String, String>>,
// Character encoding for stdout/stderr
encoding: Option<String>,
// Spawn the child in a new process group (POSIX) or job object (Windows).
// When enabled, killing the child also kills all processes in the group.
#[serde(default)]
process_group: bool,
}

#[allow(clippy::unnecessary_wraps)]
Expand Down Expand Up @@ -154,6 +158,9 @@ fn prepare_cmd<R: Runtime>(
} else {
command = command.env_clear();
}
if options.process_group {
command = command.set_process_group(true);
}

let encoding = match options.encoding {
Option::None => EncodingWrapper::Text(None),
Expand Down
Loading