Avoid "closed stream" errors from shell commands