Improve message on nonempty queue + fix child hanging on stdin

1. Improve the error reported when the child process exits before the
whole queue is processed.

2. Close stdin pipe when all commands are processed.