加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

当我在Windows上使用脚本名称运行Python脚本时,不能重定向输出

发布时间:2020-12-13 20:22:06 所属栏目:Windows 来源:网络整理
导读:这是运行在Windows 7(64位),Python 2.6与Win32扩展为Python. 我有一个简单的脚本,只是打
这是运行在Windows 7(64位),Python 2.6与Win32扩展为Python.

我有一个简单的脚本,只是打印“你好世界”.我可以用python hello.py启动它.在这种情况下,我可以将输出重定向到一个文件.但是如果我通过在命令行上输入hello.py来运行它,并重定向输出,我得到一个例外.

C:> python hello.py
hello world

C:> python hello.py >output

C:> type output
hello world

C:> hello.py
hello world

C:> hello.py >output
close failed in file object destructor:
Error in sys.excepthook:

Original exception was:

我想我在升级到Windows 7之后首先得到这个错误.我记得它应该在XP中工作.我已经看到人们谈论这个bug python-Bugs-1012692 | Can’t pipe input to a python program.但是很久以前.并没有提到任何解决方案.

有没有人经历过这个?任何人都可以帮忙

你问这个吗?

Windows: When executing Python scripts on the command line using file type
associations (i.e. starting “script.py” instead of “python script.py”),
redirects may not work unless you set a specific registry key. See
the Knowledge Base article 07000.

它在Python README中.也许这个补丁是你正在寻找的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读