繁体   English   中英

Windows - 运行.py直接运行python blah.py的行为有所不同

[英]Windows - running .py directly vs running python blah.py behaves differently

我有一个使用子进程的python脚本:

import subprocess
print "Running stuff"
subprocess.check_call(["do_stuff.bat"])
print "Stuff run"

如果这被命名为blah.py,我运行(从命令提示符):

python blah.py

我将从do_stuff.bat(或我运行的任何东西)获得输出。

如果运行如下:

blah.py

然后我没有得到do_stuff.bat的输出,只有print语句。

到目前为止在Windows Server 2003上看到.Python版本2.5.2(由于各种原因卡在那里)。 查看关联的文件类型操作,我看到:

Python.File =“C:\\ Python25 \\ python.exe”“%1”%*

所以有人可以解释这个区别吗?

我有使用线程的常见问题,但我的所有代码都在python中。 线程无法使用print写入标准输出。 只是主线程可以做到这一点。 我像这样使用了somethnig

import sys
sys.stdout.write("this was printed by thread")

我知道可能它不会帮助你使用bat文件...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM