check status of output before exiting

Signed-off-by: Sami Kerola <kerolasa@iki.fi>