(original) (raw)

Index: posixmodule.c =================================================================== --- posixmodule.c (revision 55784) +++ posixmodule.c (working copy) @@ -4793,6 +4793,9 @@ PROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo; DWORD dwProcessFlags = 0; /* no NEW_CONSOLE by default for Ctrl+C handling */ + DWORD dwVersion = 0; + DWORD dwMajorVersion = 0; + DWORD dwMinorVersion = 0; char *s1,*s2, *s3 = " /c "; const char *szConsoleSpawn = "w9xpopen.exe"; int i; @@ -4814,8 +4817,20 @@ --comshell; ++comshell; - if (GetVersion() < 0x80000000 && - _stricmp(comshell, "command.com") != 0) { + dwVersion = GetVersion(); + dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); + dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); + + if (dwMajorVersion >= 5) + { + /* Current, XP + Vista? */ + x = i + strlen(s3) + strlen(cmdstring) + 1; + s2 = (char *)alloca(x); + ZeroMemory(s2, x); + PyOS_snprintf(s2, x, "%s", cmdstring); + } + else if (dwMajorVersion == 4 && + _stricmp(comshell, "command.com") != 0) { /* NT/2000 and not using command.com. */ x = i + strlen(s3) + strlen(cmdstring) + 1; s2 = (char *)alloca(x); @@ -4836,23 +4851,23 @@ modulepath[x] = '\0'; /* Create the full-name to w9xpopen, so we can test it exists */ strncat(modulepath, - szConsoleSpawn, - (sizeof(modulepath)/sizeof(modulepath[0])) - -strlen(modulepath)); + szConsoleSpawn, + (sizeof(modulepath)/sizeof(modulepath[0])) + -strlen(modulepath)); if (stat(modulepath, &statinfo) != 0) { size_t mplen = sizeof(modulepath)/sizeof(modulepath[0]); /* Eeek - file-not-found - possibly an embedding situation - see if we can locate it in sys.prefix */ strncpy(modulepath, - Py_GetExecPrefix(), - mplen); + Py_GetExecPrefix(), + mplen); modulepath[mplen-1] = '\0'; if (modulepath[strlen(modulepath)-1] != '\\') strcat(modulepath, "\\"); strncat(modulepath, - szConsoleSpawn, - mplen-strlen(modulepath)); + szConsoleSpawn, + mplen-strlen(modulepath)); /* No where else to look - raise an easily identifiable error, rather than leaving Windows to report "file not found" - as the user is probably blissfully @@ -4861,10 +4876,10 @@ */ if (stat(modulepath, &statinfo) != 0) { PyErr_Format(PyExc_RuntimeError, - "Can not locate '%s' which is needed " - "for popen to work with your shell " - "or platform.", - szConsoleSpawn); + "Can not locate '%s' which is needed " + "for popen to work with your shell " + "or platform.", + szConsoleSpawn); return FALSE; } } @@ -4970,20 +4985,26 @@ FALSE, DUPLICATE_SAME_ACCESS); if (!fSuccess) + { return win32_error("DuplicateHandle", NULL); + } /* Close the inheritable version of ChildStdin that we're using. */ CloseHandle(hChildStdinWr); if (!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) + { return win32_error("CreatePipe", NULL); + } fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd, GetCurrentProcess(), &hChildStdoutRdDup, 0, FALSE, DUPLICATE_SAME_ACCESS); if (!fSuccess) + { return win32_error("DuplicateHandle", NULL); + } /* Close the inheritable version of ChildStdout that we're using. */ @@ -4991,14 +5012,18 @@ if (n != POPEN_4) { if (!CreatePipe(&hChildStderrRd, &hChildStderrWr, &saAttr, 0)) + { return win32_error("CreatePipe", NULL); + } fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStderrRd, GetCurrentProcess(), &hChildStderrRdDup, 0, FALSE, DUPLICATE_SAME_ACCESS); if (!fSuccess) + { return win32_error("DuplicateHandle", NULL); + } /* Close the inheritable version of ChildStdErr that we're using. */ CloseHandle(hChildStderrRd); }