python - django如何使从bash执行的python脚本将stdout写入文件?

标签 python django bash

我正在使用 Django,当我运行测试并使用命令取消警告时,我收到大量错误和弃用警告...

python -Wall manage.py test

在常规的 bash 中我通常会做这样的事情......

command > log.log

但这不起作用,或者它只是将输出的一小部分写入文件。我可以编写一个 python 脚本,但输出可能来自整个 Django 框架字,我真的宁愿将此输出放入文件中。

我还尝试了 python 命令上的 -u 选项,但也不起作用

最佳答案

如果您看到写入 stdout 和 stderr 的错误,那么您需要重定向它们:

 python -Wall manage.py test >log.log 2>&1

这里有更多关于 shell 重定向的内容:In the shell, what does " 2>&1 " mean?

关于python - django如何使从bash执行的python脚本将stdout写入文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38889156/

相关文章:

java - Java 开发者视角下的 Django

bash - svn 从 bash 脚本提交而不打开编辑器

python - 在另一个方法中运行一个方法。 Python

python - 无法从 BeautifulSoup4 中的字符串解析 'href'

python - 如何从请求帖子中解析我的 View 中的 json

django - GeoDjango - LayerMapping : An error occurred in the current transaction. 在 'atomic' block 结束之前你不能执行查询

bash - 如何通过单独的 grep 过滤器发送 stderr 和 stdout?

bash - IntelliJ 中的 zsh

Python Plotly : Percentage Axis Formatter

python - 使用 Anaconda 将 .py 转换为 .exe