mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-34044: subprocess.Popen copies startupinfo (GH-8090)
subprocess.Popen now copies the startupinfo argument to leave it unchanged: it will modify the copy, so that the same STARTUPINFO object can be used multiple times. Add subprocess.STARTUPINFO.copy() method.
This commit is contained in:
parent
09bb918a61
commit
483422f57e
3 changed files with 47 additions and 0 deletions
|
@ -2822,6 +2822,33 @@ class Win32ProcessTestCase(BaseTestCase):
|
|||
subprocess.call([sys.executable, "-c", "import sys; sys.exit(0)"],
|
||||
startupinfo=startupinfo)
|
||||
|
||||
def test_startupinfo_copy(self):
|
||||
# bpo-34044: Popen must not modify input STARTUPINFO structure
|
||||
startupinfo = subprocess.STARTUPINFO()
|
||||
startupinfo.dwFlags = subprocess.STARTF_USESHOWWINDOW
|
||||
startupinfo.wShowWindow = subprocess.SW_HIDE
|
||||
|
||||
# Call Popen() twice with the same startupinfo object to make sure
|
||||
# that it's not modified
|
||||
for _ in range(2):
|
||||
cmd = [sys.executable, "-c", "pass"]
|
||||
with open(os.devnull, 'w') as null:
|
||||
proc = subprocess.Popen(cmd,
|
||||
stdout=null,
|
||||
stderr=subprocess.STDOUT,
|
||||
startupinfo=startupinfo)
|
||||
with proc:
|
||||
proc.communicate()
|
||||
self.assertEqual(proc.returncode, 0)
|
||||
|
||||
self.assertEqual(startupinfo.dwFlags,
|
||||
subprocess.STARTF_USESHOWWINDOW)
|
||||
self.assertIsNone(startupinfo.hStdInput)
|
||||
self.assertIsNone(startupinfo.hStdOutput)
|
||||
self.assertIsNone(startupinfo.hStdError)
|
||||
self.assertEqual(startupinfo.wShowWindow, subprocess.SW_HIDE)
|
||||
self.assertEqual(startupinfo.lpAttributeList, {"handle_list": []})
|
||||
|
||||
def test_creationflags(self):
|
||||
# creationflags argument
|
||||
CREATE_NEW_CONSOLE = 16
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue