Overview
| Artifact ID: | f45d3eab32f2eaede1afa23c258bd62c642692be |
|---|---|
| Ticket: | 6dacb3b6f0381d534f37ff419ab3b1a9028d04bc
exec and open | fail for .bat files if 8dot3name is disabled and path + command contain spaces |
| User & Date: | anonymous on 2013-07-22 14:01:12 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
The issue is that quoting in tclWinPipe.c does not properly handle cases where a bat is run from GUI (which adds cmd.exe /c to run command) and arguments include quotes as well. To reproduce: - disable 8dot3name (fsutil 8dot3name set 1 from elevated command prompt) and reboot - create a dir with spaces - i.e. C:\dir with spaces - create C:\dir with spaces\test.bat - exec C:/dir with spaces/test.bat "" Tcl fails with error: 'C:/dir' is not recognized as an internal or external command. This is because internally the following command line is built: C:\Windows\system32\cmd.exe /c "C:\dir with spaces\test.bat" "" In this case (where more than 2 quotes are used in cmd /c invocation), cmd.exe strips first and last quotation mark and in turn tries to run: C:\dir with spaces\test.bat" " The proper solution is to add /s switch (which will always cause first and last quote to be stripped, regardless of number of quotes) and wrap the whole command line in quotes: C:\Windows\system32\cmd.exe /c ""C:\dir with spaces\test.bat" """ Which will in turn run: "C:\dir with spaces\test.bat" "" More information and quote from cmd.exe /?: http://stackoverflow.com/questions/355988/how-do-i-deal-with-quote-characters-when-using-cmd-exe Sample patch to fix the behavior: --- tclWinPipe.c.orig 2013-07-10 12:56:21 +0000 +++ tclWinPipe.c 2013-07-22 13:51:14 +0000 @@ -1126,7 +1126,7 @@ startInfo.wShowWindow = SW_HIDE; startInfo.dwFlags |= STARTF_USESHOWWINDOW; createFlags = CREATE_NEW_CONSOLE; - Tcl_DStringAppend(&cmdLine, "cmd.exe /c", -1); + Tcl_DStringAppend(&cmdLine, "cmd.exe /s /c", -1); } else { createFlags = DETACHED_PROCESS; } @@ -1539,6 +1539,7 @@ { const char *arg, *start, *special; int quote, i; + int entireCommandQuote = 0; Tcl_DString ds; Tcl_DStringInit(&ds); @@ -1549,7 +1550,15 @@ Tcl_DStringAppend(&ds, Tcl_DStringValue(linePtr), -1); if (Tcl_DStringLength(linePtr) > 0) { - Tcl_DStringAppend(&ds, " ", 1); + // On Windows NT, cmd /c /s requires quoting all parameters + // with a quote character in order to preserve inner quotes + // of the command to be run + if (TclWinGetPlatformId() == VER_PLATFORM_WIN32_NT) { + Tcl_DStringAppend(&ds, " \"", 2); + entireCommandQuote = 1; + } else { + Tcl_DStringAppend(&ds, " ", 1); + } } for (i = 0; i < argc; i++) { @@ -1617,6 +1626,9 @@ Tcl_DStringAppend(&ds, "\"", 1); } } + if (entireCommandQuote) { + Tcl_DStringAppend(&ds, "\"", 1); + } Tcl_DStringFree(linePtr); Tcl_WinUtfToTChar(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds), linePtr); Tcl_DStringFree(&ds); - is_private changed to: "0"
- login: "anonymous"
- priority changed to: "5 Medium"
- private_contact changed to: "07a5c627b51b39b3731e24c890e2a2dd0ec40c59"
- resolution changed to: "None"
- severity changed to: "Critical"
- status changed to: "Open"
- submitter changed to: "anonymous"
- subsystem changed to: "52. Portability Support"
- title changed to:
exec and open | fail for .bat files if 8dot3name is disabled and path + command contain spaces
- type changed to: "Bug"