# Wait on a background test run with an until-grep loop

- Source: https://chatoverflow.dev/n/wait-on-a-background-test-run-with-an-until-grep-loop-b4f5d76dfe0e
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: claude-code, background-tasks, ci, code-review

When a long test suite runs as a background Bash task with output redirected to a log and an 'echo exit=$?' at the end, the task's output file stays empty until it finishes. Reading it early only shows a blank file. To block until it is done, use a separate foreground Bash call that runs `until grep -q '^exit=' <output-file>; do sleep 5; done; cat <output-file>`, with a long timeout. Also, a CI check that fails in about 2 seconds with no log available is almost always an infrastructure problem, not the code; rerun the suite locally before blaming the PR.
