Exit codes and streams
Chapter lab: Processes
This lesson continues in the same lab as the lesson before it. If you don’t have it yet, download it here.
Or fetch and unpack it from a terminal in VS Code:
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch14-processes.zip && unzip -q ch14-processes.zip && rm ch14-processes.zipInvoke-WebRequest https://manykarim.github.io/robotframework-essentials-web/labs/ch14-processes.zip -OutFile ch14-processes.zip; Expand-Archive ch14-processes.zip -DestinationPath .; Remove-Item ch14-processes.zipOpen the folder in VS Code with code rfe-ch14-processes (or File → Open Folder…) and accept the recommended RobotCode and Python extensions. Then set it up:
uv syncpython3 -m venv .venvsource .venv/bin/activatepip install -r requirements.txtpython -m venv .venv.venv\Scripts\Activate.ps1pip install -r requirements.txtKeep the environment active in every terminal where you run lesson commands.
poetry install --no-rootPython 3.13 or newer is required; uv installs it when it is missing.
Open in browserNo setup? Try the lab right here: its files, an editor and a terminal, running in your browser.
What's inside
Directoryrfe-ch14-processes/
Directory.vscode/
- extensions.json
Directorychecks/
- smoke.robot
Directorysample_data/
- app.log
- catalog.xml
- orders.csv
- results.xml
- settings.cfg
Directorytools/
- inventory.py
- .gitignore
- .python-version
- LAB.md
- pyproject.toml
- README.md
- requirements.txt
- uv.lock
A process reports success through its exit code — 0 for success, non-zero
for a problem — and its messages through two streams: stdout for normal
output, stderr for errors. The inventory CLI exits 1 when a stock check
fails and writes the offending product to stderr. Run it yourself and check the
exit code with $?:
The error text went to stderr; the exit code says the check failed. Your test asserts on both.
Task 1 — Assert failing exit codes and stderr
Section titled “Task 1 — Assert failing exit codes and stderr”Goal: create checks/exitcodes.robot with two tests: one running a stock
check that fails (exit 1, offending product on stderr), and one running the
CLI’s fail command (exit 1).
Here is the same shape — one passing run, one failing run. Adapt it.
Worked example — adapt it, don’t copy it
*** Settings ***Library Process
*** Test Cases ***Good Run Exits Zero ${ok}= Run Process python3 tools/inventory.py list Should Be Equal As Integers ${ok.rc} 0
Bad Run Exits One ${bad}= Run Process python3 tools/inventory.py fail Should Be Equal As Integers ${bad.rc} 1 Should Not Be Empty ${bad.stderr}Done when
both failing-process tests are defined.
Hint 1
Run the stock check with its flags as separate cells:
Run Process python3 tools/inventory.py check --min-stock 10.
It exits 1.
Hint 2
The low-stock product is written to stderr — assert
Should Contain ${result.stderr} desk-lamp. Add a second test that runs
fail and checks ${result.rc} is 1.
Solution
*** Settings ***Library Process
*** Test Cases ***Stock Check Fails With Exit Code One ${result}= Run Process python3 tools/inventory.py check --min-stock 10 Should Be Equal As Integers ${result.rc} 1 Should Contain ${result.stderr} desk-lamp
Deliberate Failure Exits One ${result}= Run Process python3 tools/inventory.py fail Should Be Equal As Integers ${result.rc} 1Task 2 — Run it green
Section titled “Task 2 — Run it green”Run:
uv run robot checksrobot checkspoetry run robot checksDone when
the failing checks exit 1, and the low-stock product appears on stderr.
Check your understanding
Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.
A non-zero exit code from a process means…
By convention, 0 is success and non-zero signals a failure — the inventory CLI uses 1 for a failed check.
Show the answer
Answer: a failure or problem the caller should handle — By convention, 0 is success and non-zero signals a failure — the inventory CLI uses 1 for a failed check.
Where does a process report an error message?
Error messages conventionally go to standard error,
${result.stderr}.Show the answer
Answer:
.stderr— Error messages conventionally go to standard error,${result.stderr}.
Key terms
- exit code (rc)concept
- 0 = success, non-zero = failure; assert with
Should Be Equal As Integers ${result.rc} …. - stdout / stderrconcept
- A process's normal output vs its error output.