【发布时间】:2016-09-23 21:45:09
【问题描述】:
在 Windows 10 64 位家庭高级版上使用 python 2.7.11 从 Windows 7 就地升级
在标准控制台中,以下代码保存为 hello.py 并打印:
你好世界
调用时
python hello.py
#! python
print 'Hello World'
调用时根本不产生控制台输出
hello.py
或hello
程序在所有三种情况下都运行。
我可以通过添加来证明这一点
with open('world.txt', 'w') as fh:
fh.write('dolly\n')
调用程序的三种方法中的每一种都成功地用正确的信息编写了world.txt。
python.exe 在我的路径中
.py 在 pathext 变量中
.py 与 python.exe 关联,正确的命令行在“shell open”注册表项中。
以上均符合
https://docs.python.org/2/faq/windows.html
在没有 Windows 7 扩展的情况下,我从命令行运行 python 脚本没有问题
谢谢,
【问题讨论】:
-
更新:尝试 sys.stdout.write() 和 stderr.write() 显示相同的行为。以提升的权限运行没有帮助
-
将实际命令行写入文件:
subprocess.call('wmic process where processid=%d get commandline' % os.getpid(), stdout=fh). -
我以为我找到了答案:stackoverflow.com/questions/3018848/… 指向:support.microsoft.com/en-us/kb/321788 我的注册表已经有了正确的值