add self-adapting for stdout or file/pipe