Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 0b3d335c7f2e4c286539b74c8e3eb0dcfa67a1166a7fbdba6d6e6ec676a31994
Ticket: f91ab723f3dfbc0d2b720a70a1fa09eebfa1cde5
exec+wish fails to handle windows batch file with arguments and spaces
User & Date: anonymous on 2024-02-23 07:34:22
Changes

  1. icomment:
    When it's a batch job, i.e. something .bat, wish generates:
    
       cmd.exe /c "pa th\to.bat" "pa th/to.txt" 8
    
    and that fails. If you enter that into a windows cmd window, it also fails *because* it needs to have another set of quotes around the whole string following the /c.
    
    
    Changing that in a cmd window to:
    
       cmd.exe /c ""pa th\to.bat" "pa th/to.txt" 8"
    
    and it works.
    
    When the path to the batch file has no spaces, it does not quote that, *and* will fail if you do add quotes anyway. Now that's really weird, but in fact I saw something about that in the documentation. However, adding quotes around the entire string will also make that case work.
    
    
    
    Now, if you use tclsh and exec, it ends up being just this:
    
       "pa th\to.bat" "pa th/to.txt" 8
    
    and that works from tclsh and also in a cmd window.
    
    It's because the call to HasConsole() returns true in tclsh so that the command line is not prefixed with cmd.exe /c
    
    
    
    Here's the key code:
    
        if (HasConsole()) {
            createFlags = 0;
        } else if (applType == APPL_DOS) {
        /*
         * Under NT, 16-bit DOS applications will not run unless they can
         * be attached to a console. If we are running without a console,
         * run the 16-bit program as an normal process inside of a hidden
         * console application, and then run that hidden console as a
         * detached process.
         */
    
          startInfo.wShowWindow = SW_HIDE;
          startInfo.dwFlags |= STARTF_USESHOWWINDOW;
          createFlags = CREATE_NEW_CONSOLE;
          TclDStringAppendLiteral(&cmdLine, "cmd.exe /c");
        } else {
           createFlags = DETACHED_PROCESS;
        }
    
  2. login: "anonymous"
  3. mimetype: "text/plain"