mirror of https://github.com/python/cpython
When using shell=True on Windows, don't display a shell window by default. Fixes #1057061.
This commit is contained in:
parent
80961f3ca9
commit
c1d6536d60
|
@ -372,11 +372,11 @@ if mswindows:
|
||||||
STD_OUTPUT_HANDLE, STD_ERROR_HANDLE
|
STD_OUTPUT_HANDLE, STD_ERROR_HANDLE
|
||||||
from win32api import GetCurrentProcess, DuplicateHandle, \
|
from win32api import GetCurrentProcess, DuplicateHandle, \
|
||||||
GetModuleFileName, GetVersion
|
GetModuleFileName, GetVersion
|
||||||
from win32con import DUPLICATE_SAME_ACCESS
|
from win32con import DUPLICATE_SAME_ACCESS, SW_HIDE
|
||||||
from win32pipe import CreatePipe
|
from win32pipe import CreatePipe
|
||||||
from win32process import CreateProcess, STARTUPINFO, \
|
from win32process import CreateProcess, STARTUPINFO, \
|
||||||
GetExitCodeProcess, STARTF_USESTDHANDLES, \
|
GetExitCodeProcess, STARTF_USESTDHANDLES, \
|
||||||
CREATE_NEW_CONSOLE
|
STARTF_USESHOWWINDOW, CREATE_NEW_CONSOLE
|
||||||
from win32event import WaitForSingleObject, INFINITE, WAIT_OBJECT_0
|
from win32event import WaitForSingleObject, INFINITE, WAIT_OBJECT_0
|
||||||
else:
|
else:
|
||||||
from _subprocess import *
|
from _subprocess import *
|
||||||
|
@ -673,7 +673,19 @@ class Popen(object):
|
||||||
if not isinstance(args, types.StringTypes):
|
if not isinstance(args, types.StringTypes):
|
||||||
args = list2cmdline(args)
|
args = list2cmdline(args)
|
||||||
|
|
||||||
|
# Process startup details
|
||||||
|
default_startupinfo = STARTUPINFO()
|
||||||
|
if startupinfo == None:
|
||||||
|
startupinfo = default_startupinfo
|
||||||
|
if not None in (p2cread, c2pwrite, errwrite):
|
||||||
|
startupinfo.dwFlags |= STARTF_USESTDHANDLES
|
||||||
|
startupinfo.hStdInput = p2cread
|
||||||
|
startupinfo.hStdOutput = c2pwrite
|
||||||
|
startupinfo.hStdError = errwrite
|
||||||
|
|
||||||
if shell:
|
if shell:
|
||||||
|
default_startupinfo.dwFlags |= STARTF_USESHOWWINDOW
|
||||||
|
default_startupinfo.wShowWindow = SW_HIDE
|
||||||
comspec = os.environ.get("COMSPEC", "cmd.exe")
|
comspec = os.environ.get("COMSPEC", "cmd.exe")
|
||||||
args = comspec + " /c " + args
|
args = comspec + " /c " + args
|
||||||
if (GetVersion() >= 0x80000000L or
|
if (GetVersion() >= 0x80000000L or
|
||||||
|
@ -692,15 +704,6 @@ class Popen(object):
|
||||||
# kill children.
|
# kill children.
|
||||||
creationflags |= CREATE_NEW_CONSOLE
|
creationflags |= CREATE_NEW_CONSOLE
|
||||||
|
|
||||||
# Process startup details
|
|
||||||
if startupinfo == None:
|
|
||||||
startupinfo = STARTUPINFO()
|
|
||||||
if not None in (p2cread, c2pwrite, errwrite):
|
|
||||||
startupinfo.dwFlags |= STARTF_USESTDHANDLES
|
|
||||||
startupinfo.hStdInput = p2cread
|
|
||||||
startupinfo.hStdOutput = c2pwrite
|
|
||||||
startupinfo.hStdError = errwrite
|
|
||||||
|
|
||||||
# Start the process
|
# Start the process
|
||||||
try:
|
try:
|
||||||
hp, ht, pid, tid = CreateProcess(executable, args,
|
hp, ht, pid, tid = CreateProcess(executable, args,
|
||||||
|
|
|
@ -377,6 +377,7 @@ sp_CreateProcess(PyObject* self, PyObject* args)
|
||||||
|
|
||||||
/* note: we only support a small subset of all SI attributes */
|
/* note: we only support a small subset of all SI attributes */
|
||||||
si.dwFlags = getint(startup_info, "dwFlags");
|
si.dwFlags = getint(startup_info, "dwFlags");
|
||||||
|
si.wShowWindow = getint(startup_info, "wShowWindow");
|
||||||
si.hStdInput = gethandle(startup_info, "hStdInput");
|
si.hStdInput = gethandle(startup_info, "hStdInput");
|
||||||
si.hStdOutput = gethandle(startup_info, "hStdOutput");
|
si.hStdOutput = gethandle(startup_info, "hStdOutput");
|
||||||
si.hStdError = gethandle(startup_info, "hStdError");
|
si.hStdError = gethandle(startup_info, "hStdError");
|
||||||
|
@ -530,6 +531,8 @@ init_subprocess()
|
||||||
defint(d, "STD_ERROR_HANDLE", STD_ERROR_HANDLE);
|
defint(d, "STD_ERROR_HANDLE", STD_ERROR_HANDLE);
|
||||||
defint(d, "DUPLICATE_SAME_ACCESS", DUPLICATE_SAME_ACCESS);
|
defint(d, "DUPLICATE_SAME_ACCESS", DUPLICATE_SAME_ACCESS);
|
||||||
defint(d, "STARTF_USESTDHANDLES", STARTF_USESTDHANDLES);
|
defint(d, "STARTF_USESTDHANDLES", STARTF_USESTDHANDLES);
|
||||||
|
defint(d, "STARTF_USESHOWWINDOW", STARTF_USESHOWWINDOW);
|
||||||
|
defint(d, "SW_HIDE", SW_HIDE);
|
||||||
defint(d, "INFINITE", INFINITE);
|
defint(d, "INFINITE", INFINITE);
|
||||||
defint(d, "WAIT_OBJECT_0", WAIT_OBJECT_0);
|
defint(d, "WAIT_OBJECT_0", WAIT_OBJECT_0);
|
||||||
defint(d, "CREATE_NEW_CONSOLE", CREATE_NEW_CONSOLE);
|
defint(d, "CREATE_NEW_CONSOLE", CREATE_NEW_CONSOLE);
|
||||||
|
|
Loading…
Reference in New Issue