SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
authorTim Peters <tim.peters@gmail.com>
Mon, 27 Aug 2001 06:37:48 +0000 (06:37 +0000)
committerTim Peters <tim.peters@gmail.com>
Mon, 27 Aug 2001 06:37:48 +0000 (06:37 +0000)
Brian Quinlan.

Misc/ACKS
Misc/NEWS
Modules/posixmodule.c

index 8c6c756b15f997f8359909acbb5cc1090d16581f..67179f8ee4b42f60b0aa0f0e1b2b4662fb12d5d9 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -317,6 +317,7 @@ Fran
 John Popplewell
 Amrit Prem
 Paul Prescod
+Brian Quinlan
 Eric Raymond
 John Redford
 Terry Reedy
index 5ddf80a2ceb5b60da3e394e962806bd4bb56d71c..6cb27f0f8a538890a7731763bad230a1715ee163 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,9 @@ Tests
 
 Windows
 
++ The w9xpopen hack is now used on Windows NT and 2000 too when COMPSPEC
+  points to command.com (patch from Brian Quinlan).
+
 
 What's New in Python 2.2a2?
 ===========================
index 403bae14862de20143de533eced415d7fc1c5a5d..c1ec84a13e9fcc624e3b7943f4dba2df9c031c6d 100644 (file)
@@ -2403,13 +2403,23 @@ _PyPopenCreateProcess(char *cmdstring,
        int x;
 
        if (i = GetEnvironmentVariable("COMSPEC",NULL,0)) {
+               char *comshell;
+
                s1 = (char *)_alloca(i);
                if (!(x = GetEnvironmentVariable("COMSPEC", s1, i)))
                        return x;
-               if (GetVersion() < 0x80000000) {
-                       /*
-                        * NT/2000
-                        */
+
+               /* Explicitly check if we are using COMMAND.COM.  If we are
+                * then use the w9xpopen hack.
+                */
+               comshell = s1 + x;
+               while (comshell >= s1 && *comshell != '\\')
+                       --comshell;
+               ++comshell;
+
+               if (GetVersion() < 0x80000000 &&
+                   _stricmp(comshell, "command.com") != 0) {
+                       /* NT/2000 and not using command.com. */
                        x = i + strlen(s3) + strlen(cmdstring) + 1;
                        s2 = (char *)_alloca(x);
                        ZeroMemory(s2, x);
@@ -2417,8 +2427,8 @@ _PyPopenCreateProcess(char *cmdstring,
                }
                else {
                        /*
-                        * Oh gag, we're on Win9x. Use the workaround listed in
-                        * KB: Q150956
+                        * Oh gag, we're on Win9x or using COMMAND.COM. Use
+                        * the workaround listed in KB: Q150956
                         */
                        char modulepath[_MAX_PATH];
                        struct stat statinfo;
@@ -2454,7 +2464,8 @@ _PyPopenCreateProcess(char *cmdstring,
                                if (stat(modulepath, &statinfo) != 0) {
                                        PyErr_Format(PyExc_RuntimeError, 
                                            "Can not locate '%s' which is needed "
-                                           "for popen to work on this platform.",
+                                           "for popen to work with your shell "
+                                           "or platform.",
                                            szConsoleSpawn);
                                        return FALSE;
                                }
@@ -2478,7 +2489,9 @@ _PyPopenCreateProcess(char *cmdstring,
        /* Could be an else here to try cmd.exe / command.com in the path
           Now we'll just error out.. */
        else {
-               PyErr_SetString(PyExc_RuntimeError, "Can not locate a COMSPEC environment variable to use as the shell");
+               PyErr_SetString(PyExc_RuntimeError,
+                       "Cannot locate a COMSPEC environment variable to "
+                       "use as the shell");
                return FALSE;
        }
   
@@ -2507,7 +2520,7 @@ _PyPopenCreateProcess(char *cmdstring,
                *hProcess = piProcInfo.hProcess;
                return TRUE;
        }
-       win32_error("CreateProcess", NULL);
+       win32_error("CreateProcess", s2);
        return FALSE;
 }