views:

43

answers:

2

I'm using python 2.7 on Windows to automate batch RAW conversions using dcraw and PIL.

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.

I'm involving it like so:

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

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)

A: 

Renaming to .pyw will run without any console.

Jason Scheirer
+1  A: 

You need to set the startupinfo parameter when calling Popen.

Here you have an example at Activestate.com Recipes

Ricardo Reyes