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

标签 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。

最佳答案

某些类型的控制台消息将绕过输出重定向(或调用任何使用“>”的内容)。我注意到 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

关于python - 将 django manage.py 输出(在 Windows 中)重定向到文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5215106/

相关文章:

python - Project Euler 10 - 为什么第一个 python 代码比第二个运行得快得多?

python - Thrift Python 客户端中具有默认值的默认参数

python - 将 netCDF 数据存储到 couchbase 中

c - 在 Windows 中区分 cmd 行参数和拖动到图标参数的方法?

python - Django makemessage 命令不处理应用程序

python - 自定义 django auth 后端不使用基本登录 View 记录用户

python - pandas:将两列以上映射到一列

windows - 为什么特定的 Windows 批处理参数会导致崩溃?

Windows 内核驱动程序签名和服务创建

django - 如何清除 Django 中旧 SESSION_COOKIE_DOMAIN 的 cookie