P Preserve Status / Preserve Exit Status On Timeout
Preserve Exit Status On Timeout
Preserves the exit status of commands after a timeout.
timeout -p <1s|1m|1h|1d|...> <command> timeout -p <1s|1m|1h|1d|...> <command> #!/bin/bash
# Preserve Exit Status On Timeout
timeout {{[-p|--preserve-status]}} {{1s|1m|1h|1d|...}} {{command}} import subprocess
# Preserve Exit Status On Timeout
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"p---preserve-status",
"-p",
"<1s|1m|1h|1d|...>",
"<command>"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: p---preserve-status not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
In environments where subsequent commands depend on the exit status of time-limited operations
Pro Tip
Integrate with CI/CD pipelines to maintain accurate feedback on success or failure states.
Command Builder
Tune the command before you copy it
timeout -p <1s|1m|1h|1d|...> <command> Anatomy of Output
Understanding the result
Command executed successfully before timeout: exit code 0 Execution Info Reflects the successful completion of the command.
Timeout process completed gracefully Completion Message Confirms successful operation and completion.
Final exit status preserved: 0 Exit Status Indicates the outcome of command execution.
Power User Variants
Optimized versions
p---preserve-status sleep 2 Preserves exit code of the command even if it times out.
p---preserve-status timeout 10s some_other_command Parentheses preserve exit status through timeout.
Troubleshooting
Common pitfalls
timeout: command failed to execute
Solution: Check command syntax and environment compatibility.
timeout: invalid duration specified
Solution: Ensure the duration format adheres to required standards.
timeout: unable to preserve status
Solution: Investigate environment factors preventing exit status capture.
Command Breakdown
What each part is doing
-
timeout - Base Command
- The executable that performs this operation. Here it runs P Preserve Status before the shell applies any redirect operators.
-
-p - p| preserve status
- The value supplied for p| preserve status.
-
<1s|1m|1h|1d|...> - 1s|1m|1h|1d|...
- The value supplied for 1s|1m|1h|1d|....
-
<command> - command
- The value supplied for command.
-
-p - Command Option
- Tool-specific option used by this command invocation.
Alternative Approaches
Comparable commands in other tools
Alternative system operations tools for the same job.