[Tutor] os.system vs subprocess.Popen args problems
eryksun
eryksun at gmail.com
Wed Sep 4 12:42:05 CEST 2013
On Wed, Sep 4, 2013 at 6:22 AM, Oscar Benjamin
<oscar.j.benjamin at gmail.com> wrote:
> On 4 September 2013 11:11, eryksun <eryksun at gmail.com> wrote:
>
>> Using shell=True also sets startupinfo to hide the window. If that's
>> the only reason you're using the shell, you may as well cut out the
>> middleman (and potential security hole). Set startupinfo=si, where si
>> is defined like this:
>
> I think it should just be possible to use shell=False here.
>
>> 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.
http://docs.python.org/2/library/subprocess#subprocess.STARTUPINFO
STARTUPINFO struct:
http://msdn.microsoft.com/en-us/library/ms686331
PC/_subprocess.c:
/* note: we only support a small subset of all SI attributes */
si.dwFlags = getint(startup_info, "dwFlags");
si.wShowWindow = getint(startup_info, "wShowWindow");
si.hStdInput = gethandle(startup_info, "hStdInput");
si.hStdOutput = gethandle(startup_info, "hStdOutput");
si.hStdError = gethandle(startup_info, "hStdError");
http://hg.python.org/cpython/file/ab05e7dd2788/PC/_subprocess.c#l444
More information about the Tutor
mailing list