【问题标题】:Redirecting django manage.py output (in windows) to a text file将 django manage.py 输出(在 Windows 中)重定向到文本文件
【发布时间】:2011-07-10 01:30:48
【问题描述】:

我正在尝试将输出从 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 32bit SP1 和 Django SVN。

【问题讨论】:

    标签: python windows django command-line stdout


    【解决方案1】:

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

    【讨论】:

    • 这正是我想要的。谢谢!
    猜你喜欢
    • 2012-12-17
    • 2013-04-21
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-09
    • 1970-01-01
    相关资源
    最近更新 更多