Skip to main content

wrap_command_with_timeout

Function wrap_command_with_timeout 

Source
pub fn wrap_command_with_timeout(command: &str, duration_secs: f64) -> String
Expand description

Wrap a command with the timeout utility

Creates a wrapper command: timeout -k {kill_after}s {duration}s sh -lc '{command}'

The use of sh -lc ensures a login shell is used, which properly loads environment variables like PATH from ~/.profile or /etc/profile.

§Arguments

  • command - The command to wrap (should be pre-escaped)
  • duration_secs - Timeout duration in seconds (supports fractional seconds like 0.5)

§Returns

A wrapped command string that includes timeout logic