将django manage.py输出(在Windows中)重定向到文本文件

时间:2011-03-07 02:09:20

标签: python windows django command-line stdout

我正在尝试将manage.py的输出重定向到文本文件,但只有一些输出被重定向到文本文件。如何将所有输出重定向到文本文件?

我的命令提示符:

C:\Development\web-py\p1st2\pianos1st-system>python manage.py test > test_results.txt
.....................................................................................................................
----------------------------------------------------------------------
Ran 117 tests in 2.026s

OK

我的test_results.txt文件:

Creating test database for alias 'default'...
Destroying test database for alias 'default'...

我正在使用Windows 7 32位SP1和Django SVN。

1 个答案:

答案 0 :(得分:22)

某些类型的控制台消息将绕过输出重定向(或使用“>”调用的任何内容)。我注意到sys.stderr.write()就是这样做的。

最后添加“2>& 1”有助于此:

python manage.py test purchaseplans > test_results.txt 2>&1

编辑:解释发生了什么:
http://en.wikipedia.org/wiki/Redirection_(computing)#Redirecting_to_and_from_the_standard_file_handles