Command Execution
Cheat sheet · https://pcornel.dk/topic.php?topic=5226
Answer
Command execution is when a script runs an external program or OS command. Do it safely by passing arguments as a list (not a shell string), setting the working directory and timeout, and checking the exit code and output.
Remember
- Command started ≠ command completed correctly; process creation proves only the execution boundary began.
- Exit code 0 ≠ target state verified; external tools may report success before asynchronous work completes.
- Quoted string ≠ safe command construction automatically; shell interpolation and platform quoting rules can still reinterpret input.
- Captured stdout ≠ full result; stderr, exit status, timeout, signals and target-side state can carry the actual failure.
First checks
shellcheck script.sh— quoting issues- subprocess.run([...], check=True) (Python) — no shell
- Start-Process / & with argument arrays — PowerShell
Verify in this order
script → command with args → exit code + output
Where it usually breaks
Process creation or even exit code zero proves only the external command's process result; it does not prove asynchronous or remote side effects reached the intended state.
Script/input → command/module binding → local/remoting session → request accepted → command result → target object read-back → effective runtime state → workload.
Command Execution scripting boundary map
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Input / runtime | Effective inputs, runtime, working context and dependency versions are explicit | Hidden defaults, stale environment, wrong interpreter/path or unvalidated input |
| Logic / execution | Branch/function/module decisions and external actions expose per-operation results | Swallowed failures, shell reinterpretation, blind retries or last-result-wins behavior |
| Result / proof | Exit/exception/log evidence is correlated with independent target read-back | Process success or printed output treated as target success |
| Recovery / troubleshooting | First failed boundary is preserved, changed minimally and retested | Random edits, catch-all suppression or evidence destroyed before diagnosis |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5226