Skip to content
Tcl Source Code History Of Ticket 6dacb3b6f0381d53
Login

History Of Ticket 6dacb3b6f0381d53

Artifacts Associated With Ticket 6dacb3b6f0381d53

  1. Ticket change [f45d3eab32] (rid 132961) by anonymous on 2013-07-22 14:01:12:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. 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);
      
    5. is_private initialized to: "0"
    6. login: "anonymous"
    7. priority initialized to: "5 Medium"
    8. private_contact initialized to: "07a5c627b51b39b3731e24c890e2a2dd0ec40c59"
    9. resolution initialized to: "None"
    10. severity initialized to: "Critical"
    11. status initialized to: "Open"
    12. submitter initialized to: "anonymous"
    13. subsystem initialized to: "52. Portability Support"
    14. title initialized to:
      exec and open | fail for .bat files if 8dot3name is disabled and path + command contain spaces
      
    15. type initialized to: "Bug"
  2. Ticket change [6baeb86727] (rid 258029) by serhiy.storchaka on 2026-10-14 15:33:39:

    1. foundin changed to: "8.6.18, 9.0.5, 9.1.0"
    2. 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.
      
    3. login: "serhiy.storchaka"
    4. mimetype: "text/x-fossil-wiki"
  3. Ticket change [ba95bbdfe8] (rid 260422) by serhiy.storchaka on 2026-10-25 08:54:48:

    1. icomment:
      The fix is rebased onto main as [/timeline?r=bug-f91ab723f3-quoting-main|bug-f91ab723f3-quoting-main], see [f91ab723f3].
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
  4. Ticket change [fbe612b773] (rid 261696) by oehhar on 2026-11-14 18:26:36:

    1. closedate changed to: "2461359.2684832756"
    2. closer changed to: "oehhar"
    3. icomment:
      Fixed by: [f91ab723]
      
      Closing.
      
      And by the way: Wojciech, I love your book !
      
      Thanks,
      Harald
      
    4. login: "oehhar"
    5. mimetype: "text/x-fossil-wiki"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "oehhar"