无法将python脚本结果重定向到Windows中的文本文件 [英] Unable to redirect python script result to a text file in windows

查看:70
本文介绍了无法将python脚本结果重定向到Windows中的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的python代码.我正在尝试在python中进行弹性搜索.

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")

我正在尝试本教程 pyes

问题是,当我尝试在Windows中运行此python脚本时,我在msdos提示符下收到一条详细消息,我不知道它是否是错误或其他任何东西.

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

但是log.txt为空.

But log.txt is empty.

出了什么问题.

推荐答案

可能是将这些消息打印到STDERR.尝试执行以下操作:

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

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

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

这也会将STDERR重定向到STDOUT.然后,您应该会看到这些消息.

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

这篇关于无法将python脚本结果重定向到Windows中的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆