Windows - 直接运行 .py 与运行 python blah.py 的行为不同 [英] Windows - running .py directly vs running python blah.py behaves differently

查看:38
本文介绍了Windows - 直接运行 .py 与运行 python blah.py 的行为不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a python script that uses subprocess:

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

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

If this was named blah.py, and I run (from a command prompt):

python blah.py

我将从 do_stuff.bat(或我运行的任何文件)获取输出.

I will get the output from do_stuff.bat (or whatever I run).

如果运行如下:

blah.py

然后我没有从 do_stuff.bat 得到输出,只有打印语句.

Then I do not get output from do_stuff.bat, only the print statements.

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

So far seen on windows Server 2003. Python version 2.5.2 (stuck there for various reasons). Looking at the associated file type action I see:

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

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

那么谁能解释一下其中的区别?

So can anyone explain the difference?

推荐答案

我在使用线程时遇到了常见问题,但我的所有代码都是在 python 中编写的.线程不能使用打印写入标准输出.只有主线程可以做到这一点.我用过这样的东西

I had common problem using threads, but all of my code was in python. Threads can not write to standard output using print. Just main thread could do that. I used somethnig like this

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

我知道它可能无法帮助您处理 bat 文件...

I know that probably it wont help you with bat file...

这篇关于Windows - 直接运行 .py 与运行 python blah.py 的行为不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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