Artifacts Associated With Ticket 6dacb3b6f0381d53
Ticket change [f45d3eab32] (rid 132961) by anonymous on 2013-07-22 14:01:12:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized 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 initialized to: "0"
- login: "anonymous"
- priority initialized to: "5 Medium"
- private_contact initialized to: "07a5c627b51b39b3731e24c890e2a2dd0ec40c59"
- resolution initialized to: "None"
- severity initialized to: "Critical"
- status initialized to: "Open"
- submitter initialized to: "anonymous"
- subsystem initialized to: "52. Portability Support"
- title initialized to:
exec and open | fail for .bat files if 8dot3name is disabled and path + command contain spaces
- type initialized to: "Bug"
Ticket change [6baeb86727] (rid 258029) by serhiy.storchaka on 2026-10-14 15:33:39:
- foundin changed to: "8.6.18, 9.0.5, 9.1.0"
- icomment:
Still reproducible with wish 8.6.18, 9.0.5 and 9.1, for a batch file in a directory with spaces and any argument that needs quoting; tclsh works. It also happens with 8dot3 names enabled. Proposed fix in branch [/timeline?r=bug-f91ab723f3-quoting|bug-f91ab723f3-quoting] (against 8.6), see [f91ab723f3]: the command after <code>cmd.exe /c</code> is enclosed in quotes, as suggested here.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
Ticket change [ba95bbdfe8] (rid 260422) by serhiy.storchaka on 2026-10-25 08:54:48:
- icomment:
The fix is rebased onto main as [/timeline?r=bug-f91ab723f3-quoting-main|bug-f91ab723f3-quoting-main], see [f91ab723f3].
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [fbe612b773] (rid 261696) by oehhar on 2026-11-14 18:26:36:
- closedate changed to: "2461359.2684832756"
- closer changed to: "oehhar"
- icomment:
Fixed by: [f91ab723] Closing. And by the way: Wojciech, I love your book ! Thanks, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "oehhar"