fix occasional stdin non-termination, #100

This is the fix for #100 proposed by @jhthorsen. I've been using it, it works great.