Ols*_*son 6 python windows subprocess popen
我在Windows上使用python 2.7来使用dcraw和PIL自动执行批量RAW转换.
问题是我每次运行dcraw时都会打开一个Windows控制台(每隔几秒就会发生一次).如果我使用.py运行脚本它不那么烦人,因为它只打开主窗口,但我更愿意只呈现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))
Run Code Online (Sandbox Code Playgroud)
感谢Ricardo Reyes
次要修订到配方,在2.7看来,你需要得到STARTF_USESHOWWINDOW来自_subprocess(您也可以使用pywin32,如果你想要的东西,可能有点不太容易发生变化),所以为后人:
suinfo = subprocess.STARTUPINFO()
suinfo.dwFlags |= _subprocess.STARTF_USESHOWWINDOW
proc = subprocess.Popen(args, -1, stdout=subprocess.PIPE, startupinfo=suinfo)
Run Code Online (Sandbox Code Playgroud)
调用Popen时需要设置startupinfo参数.
以下是Activestate.com食谱的示例:
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"])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2357 次 |
| 最近记录: |