1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Direct execution of privileged commands via `pkexec`.
//!
//! This module provides a lightweight interface for executing system commands with
//! root privileges, capturing the output (`stdout`), and
//! handling error conditions (`stderr`) cleanly.
/**
* command_pkexec.rs
*
* (C) 2026 AtlantisOS Project
* by @NachtsternBuild
*
* License: GNU GENERAL PUBLIC LICENSE Version 3
*/
use Command;
/// Executes a command with elevated privileges via `pkexec` and waits for it to finish.
///
/// This function blocks the current thread until the command (and
/// user authentication) is complete. It is particularly suitable
/// for CLI tools or background tasks that do not require direct
/// UI feedback (such as a spinner).
///
/// # Arguments
/// * `args` - A slice of string references containing the command and its parameters.
///
/// # How it works
/// 1. Starts a new process using the `pkexec` program.
/// 2. Passes the argument list to the process.
/// 3. Captures the complete output after the process terminates.
///
/// # Error Handling
/// - On success, the contents of `stdout` are output with the prefix `[INFO]`.
/// - If the command fails (exit code != 0), `stderr` is printed with the prefix `[ERROR]`.
/// - If `pkexec` itself cannot be started, an error message is printed to the standard error output.
///
/// # Usage:
/// args are list of arguments (e.g. ["apt", "update"])
///
/// ```rust
/// fn main() {
/// command_pkexec(&["ls", "/root"]);
/// }
/// ```