Mark,

My apologies for being a day late, got working on some other things.
So here's the scoop as it relates to the issue at hand:

- If you run rt.bat from the trunk as-is and place it in a path that contains an empty space, you receive the error outlined in resultwithspace.txt.

- If you run rt.bat from the trunk as-is and place it in a path that does not contain an empty space, you receive no errors as outlined in resultwithoutspace.txt.

- If you run rt.bat with the patch, on Windows XP, you receive no errors as outlined in resultafterpatch.txt.

The patch is attached. Probably my biggest question now is the use of GetVersion as opposed to GetVersionEx. According to the MSDN, it doesn't appear to be all that undesirable:

http://msdn2.microsoft.com/en-us/library/ms724451.aspx

Your thoughts?

Joseph Armbruster


Joseph Armbruster wrote:
Mark,

Sounds good, I will get patching tonight.  Any thoughts on CreateProcessW ?

Joseph Armbruster

On 6/4/07, *Mark Hammond* < [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

     > All,
     >
     > I wanted to pass this one around before opening an issue on it.
     > When running the unit test for popen via rt.bat (in PCBuild8),
     > I received the following error:
     >
     > === BEGIN ERROR ===
     >
     > C:\Documents and
     > Settings\joe\Desktop\Development\Python\trunk\PCbuild8>rt test_popen
     > Deleting .pyc/.pyo files ...
     > 43 .pyc deleted, 0 .pyo deleted
     >
     > C:\Documents and
     > Settings\joe\Desktop\Development\Python\trunk\PCbuild8>win32Re
     > lease\python.exe -E -tt ../lib/test/regrtest.py test_popen
     > test_popen
     > test test_popen failed -- Traceback (most recent call last):
     >    File "C:\Documents and Settings\joe\Desktop\Development\Python\...

    I can't reproduce this.  I expect you will find it is due to the
    space in
    the filename of your Python directory, via cmd.exe's documented
    behaviour
    with quote characters.  A patch that allows the test suite to work
    in such
    an environment would be welcome, but I think you might end up
    needing access
    to GetShortPathName() rather than CreateProcess().

    Cheers,

    Mark



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);
         }
C:\Documents and 
Settings\joe\Desktop\Development\Python\trunk\PCbuild8>win32Release\python.exe  
-E -tt ../lib/test/regrtest.py te
st_popen
test_popen
1 test OK.
About to run again without deleting .pyc/.pyo first:
Press any key to continue . . .

C:\trunk\PCbuild8>win32Release\python.exe  -E -tt ../lib/test/regrtest.py 
test_popen
test_popen
1 test OK.
About to run again without deleting .pyc/.pyo first:
Press any key to continue . . .

C:\trunk\PCbuild8>win32Release\python.exe  -E -tt ../lib/test/regrtest.py 
test_popen
test_popen
1 test OK.
C:\Documents and 
Settings\joe\Desktop\Development\Python\trunk\PCbuild8>win32Release\python.exe  
-E -tt ../lib/test/regrtest.py te
st_popen
test_popen
test test_popen failed -- Traceback (most recent call last):
  File "C:\Documents and 
Settings\joe\Desktop\Development\Python\trunk\lib\test\test_popen.py", line 31, 
in test_popen
    ["foo", "bar"]
  File "C:\Documents and 
Settings\joe\Desktop\Development\Python\trunk\lib\test\test_popen.py", line 24, 
in _do_test_commandline
    got = eval(data)[1:] # strip off argv[0]
  File "<string>", line 0

   ^
SyntaxError: unexpected EOF while parsing

1 test failed:
    test_popen
About to run again without deleting .pyc/.pyo first:
Press any key to continue . . .
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to