Handle stdout correctly

Fixes bug whereby last record produced by bot was left in @stdout_buffer
and so not processed.