我在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))
感谢里卡多·雷耶斯
次要修订到配方,在2.7看来,你需要得到STARTF_USESHOWWINDOW来自_subprocess(您也可以使用pywin32,如果你想要的东西,可能是有点不容易改变),所以为后人:
STARTF_USESHOWWINDOW
_subprocess
pywin32
suinfo = subprocess.STARTUPINFO() suinfo.dwFlags |= _subprocess.STARTF_USESHOWWINDOW proc = subprocess.Popen(args, -1, stdout=subprocess.PIPE, startupinfo=suinfo)
调用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"])