Why an AI agent's shell command showed no output: stdout buffering when not a terminal

A developer found that Claude Code's Bash tool reported a script as still running after two minutes, with its output file empty, even though the script printed a line every second when run manually. The article attributes this to C and Python libraries switching stdout to block buffering when it is not connected to a terminal, which an agent's shell capture is not. Output therefore sits in memory until the buffer fills, the program flushes, or it exits, as documented in glibc and Python's sys docs. The author notes that Node handles pipe writes differently, with its own risk of losing output on process.exit(). Suggested fixes include setting PYTHONUNBUFFERED for Python children, using stdbuf for C programs on Linux, or adding PTY support to the tool.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in