2014-05-13 73 views
0

我有一个python程序,它使我尝试从命令行执行一些打印。我想将输出重定向到一个文件,并在shell中看到打印。我试过cmd > file,cmd >> filecmd &> file。但有了这三个命令,打印既不在外壳中,也不在文件中。为什么?将程序输出重定向到文件和外壳程序

+2

'CMD 2>&1 | tee文件' – devnull

+0

@glennjackman我猜想引用的dup总结得非常好。这里没有什么新东西。 (虽然找到合适的dup需要一段时间:) – devnull

+0

@glennjackman你的外壳黄金徽章会在一次点击中神奇地关闭它。请参阅http://meta.stackoverflow.com/questions/254589/when-did-i-get-superpowers – devnull

回答

1

输出写入到文件,并比猫阅读:

python myscript.py >> output.txt | cat output.txt