| Crates.io | sal-process |
| lib.rs | sal-process |
| version | 0.1.0 |
| created_at | 2025-07-01 05:49:37.915034+00 |
| updated_at | 2025-07-01 05:49:37.915034+00 |
| description | SAL Process - Cross-platform process management and command execution |
| homepage | |
| repository | https://git.threefold.info/herocode/sal |
| max_upload_size | |
| id | 1732795 |
| size | 125,987 |
The sal-process package provides comprehensive functionality for managing and interacting with system processes across different platforms (Windows, macOS, and Linux).
Add this to your Cargo.toml:
[dependencies]
sal-process = "0.1.0"
use sal_process::{run_command, run_silent};
// Run a command and capture output
let result = run_command("echo hello world")?;
println!("Output: {}", result.stdout);
// Run a command silently
let result = run_silent("ls -la")?;
use sal_process::run;
// Use the builder pattern for more control
let result = run("echo test")
.silent(true)
.die(false)
.log(true)
.execute()?;
use sal_process::{which, process_list, process_get, kill};
// Check if a command exists
if let Some(path) = which("git") {
println!("Git found at: {}", path);
}
// List all processes
let processes = process_list("")?;
println!("Found {} processes", processes.len());
// Find processes by pattern
let chrome_processes = process_list("chrome")?;
// Get a single process (errors if 0 or >1 matches)
let process = process_get("unique_process_name")?;
// Kill processes by pattern
kill("old_server")?;
let script = r#"
echo "Starting script"
export VAR="test"
echo "Variable: $VAR"
echo "Script complete"
"#;
let result = run_command(script)?;
The package provides full Rhai integration for scripting:
// Basic command execution
let result = run_command("echo hello");
print(result.stdout);
// Builder pattern
let result = run("echo test")
.silent()
.ignore_error()
.execute();
// Process management
let git_path = which("git");
if git_path != () {
print(`Git found at: ${git_path}`);
}
let processes = process_list("chrome");
print(`Found ${processes.len()} Chrome processes`);
The package provides comprehensive error handling:
use sal_process::{run, RunError};
match run("some_command").execute() {
Ok(result) => {
if result.success {
println!("Command succeeded: {}", result.stdout);
} else {
println!("Command failed with code: {}", result.code);
}
}
Err(RunError::CommandExecutionFailed(e)) => {
eprintln!("Failed to execute command: {}", e);
}
Err(e) => {
eprintln!("Other error: {}", e);
}
}
The run() function returns a builder with these options:
.silent(bool): Suppress output to stdout/stderr.die(bool): Return error if command fails (default: true).log(bool): Log command execution.async_exec(bool): Run command asynchronouslyThe package handles platform differences automatically:
cmd.exe for script execution/bin/bash with -e flag for error handlingwmic on Windows, ps on Unix)where on Windows, which on UnixRun the test suite:
cargo test
The package includes comprehensive tests:
tempfile: For temporary script file creationrhai: For Rhai scripting integrationanyhow: For error handlingsal-text: For text processing utilitiesPlatform-specific dependencies:
nix (Unix): For Unix-specific process operationswindows (Windows): For Windows-specific process operations