[Tutor] os.system vs subprocess.Popen args problems

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Sep 4 13:11:25 CEST 2013


On 4 September 2013 11:42, eryksun <eryksun at gmail.com> wrote:
>>>     si = subprocess.STARTUPINFO()
>>>     si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
>>>     si.wShowWindow = subprocess.SW_HIDE
>>
>> Do these statements modify module-level state? Or do you need to pass
>> startupinfo=si when calling Popen?
>
> It's a documented option for instances of Popen, to configure a few
> fields in the STARTUPINFO struct that gets passed to CreateProcess.

It's not clear from the docs (or your explanation) whether the lines
above modify a global STARTUPINFO struct that gives default behaviour
to subprocesses or if it is just the way to initialise one that can be
passed to Popen or the convenience APIs. I guess the latter in which
case it's probably better to be explicit and say:

si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
si.wShowWindow = subprocess.SW_HIDE
subprocess.check_call(cmdargs, startupinfo=si)


Oscar


More information about the Tutor mailing list