Skip to main content

run_cmd

Function run_cmd 

Source
pub fn run_cmd(cmd: &str) -> String
Expand description

Run a shell command and return trimmed stdout.

§Safety

CRITICAL: Only use with hardcoded, trusted command strings. Never interpolate user input, file paths, or any external data into cmd. This function uses sh -c which enables shell injection if user data is included.

For user-provided values, use std::process::Command directly:

std::process::Command::new("cat").arg(user_path).output()

Returns an empty string on failure. Stderr is discarded — callers should not mix error output with data.