问题描述
可能重复:
在没有控制台的情况下使用 Popen 在 pythonw 中运行进程一个>
我在 Windows 上使用 python 2.7 使用 dcraw 和 PIL 自动进行批量 RAW 转换.
I'm using python 2.7 on Windows to automate batch RAW conversions using dcraw and PIL.
问题是我每次运行 dcraw 时都会打开一个 Windows 控制台(每隔几秒钟发生一次).如果我使用 .py 文件运行脚本,它就不会那么烦人,因为它只打开主窗口,但我更愿意只显示 GUI.
The problem is that I open a windows console whenever I run dcraw (which happens every couple of seconds). If I run the script using as a .py it's less annoying as it only opens the main window, but I would prefer to present only the GUI.
我是这样参与的:
args = [this.dcraw] + shlex.split(DCRAW_OPTS) + [rawfile]
proc = subprocess.Popen(args, -1, stdout=subprocess.PIPE)
ppm_data, err = proc.communicate()
image = Image.open(StringIO.StringIO(ppm_data))
<小时>
感谢里卡多·雷耶斯
Thanks to Ricardo Reyes
对该配方的小修改,在 2.7 中,您似乎需要从 _subprocess 获取 STARTF_USESHOWWINDOW(如果您也可以使用 pywin32想要一些不太容易改变的东西),所以为了后代:
Minor revision to that recipe, in 2.7 it appears that you need to get STARTF_USESHOWWINDOW from _subprocess (you could also use pywin32 if you want something that might be a little less prone to change), so for posterity:
suinfo = subprocess.STARTUPINFO()
suinfo.dwFlags |= _subprocess.STARTF_USESHOWWINDOW
proc = subprocess.Popen(args, -1, stdout=subprocess.PIPE, startupinfo=suinfo)
推荐答案
调用Popen时需要设置startupinfo参数.
You need to set the startupinfo parameter when calling Popen.
这是一个来自 Activestate.com 食谱的示例:
Here's an example from an Activestate.com Recipe:
import subprocess
def launchWithoutConsole(command, args):
"""Launches 'command' windowless and waits until finished"""
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
return subprocess.Popen([command] + args, startupinfo=startupinfo).wait()
if __name__ == "__main__":
# test with "pythonw.exe"
launchWithoutConsole("d:\bin\gzip.exe", ["-d", "myfile.gz"])
这篇关于如何从 Python (2.7) 中生成的进程中消除 Windows 控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)