Unable to redirect python script result to a text file in windows

自作多情 提交于 2019-12-11 17:57:57

问题


Here is my python code.I'm trying to do elastic search in python.

from pyes import *
from pyes.mappings import *
conn = ES('http://search.twitter.com/search.json?q=poplio')
conn.indices.create_index("test-index")

I'm trying this tutorial pyes

The issue is when i try to run this python script in windows i get a detailed message on msdos prompt which i don't know if its an error or any thing else.

So i tried to redirect that message to a text file but i don't see any thing in that file.

Here is how i redirect the output of script

python script.py > log.txt

But log.txt is empty.

What is going wrong.


回答1:


It might be printing those messages to STDERR. Try doing the following:

python script.py > log.txt 2>&1

This will redirect the STDERR to STDOUT as well. You should see those messages then.



来源:https://stackoverflow.com/questions/15927290/unable-to-redirect-python-script-result-to-a-text-file-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!