Skip to content
Tcl Source Code Artifact [0b3d335c7f]
Login

Artifact [0b3d335c7f]

Artifact 0b3d335c7f2e4c286539b74c8e3eb0dcfa67a1166a7fbdba6d6e6ec676a31994:

Ticket change [0b3d335c7f] - Ticket [f91ab723f3dfbc0d|f91ab723f3] <i>exec+wish fails to handle windows batch file with arguments and spaces</i> status still Open with 3 other changes by anonymous on 2024-02-23 07:34:22.
D 2024-02-23T07:34:22.504
J icomment When\sit's\sa\sbatch\sjob,\si.e.\ssomething\s.bat,\swish\sgenerates:\r\n\r\n\s\s\scmd.exe\s/c\s"pa\sth\\to.bat"\s"pa\sth/to.txt"\s8\r\n\r\nand\sthat\sfails.\sIf\syou\senter\sthat\sinto\sa\swindows\scmd\swindow,\sit\salso\sfails\s*because*\sit\sneeds\sto\shave\sanother\sset\sof\squotes\saround\sthe\swhole\sstring\sfollowing\sthe\s/c.\r\n\r\n\r\nChanging\sthat\sin\sa\scmd\swindow\sto:\r\n\r\n\s\s\scmd.exe\s/c\s""pa\sth\\to.bat"\s"pa\sth/to.txt"\s8"\r\n\r\nand\sit\sworks.\r\n\r\nWhen\sthe\spath\sto\sthe\sbatch\sfile\shas\sno\sspaces,\sit\sdoes\snot\squote\sthat,\s*and*\swill\sfail\sif\syou\sdo\sadd\squotes\sanyway.\sNow\sthat's\sreally\sweird,\sbut\sin\sfact\sI\ssaw\ssomething\sabout\sthat\sin\sthe\sdocumentation.\sHowever,\sadding\squotes\saround\sthe\sentire\sstring\swill\salso\smake\sthat\scase\swork.\r\n\r\n\r\n\r\nNow,\sif\syou\suse\stclsh\sand\sexec,\sit\sends\sup\sbeing\sjust\sthis:\r\n\r\n\s\s\s"pa\sth\\to.bat"\s"pa\sth/to.txt"\s8\r\n\r\nand\sthat\sworks\sfrom\stclsh\sand\salso\sin\sa\scmd\swindow.\r\n\r\nIt's\sbecause\sthe\scall\sto\sHasConsole()\sreturns\strue\sin\stclsh\sso\sthat\sthe\scommand\sline\sis\snot\sprefixed\swith\scmd.exe\s/c\r\n\r\n\r\n\r\nHere's\sthe\skey\scode:\r\n\r\n\s\s\s\sif\s(HasConsole())\s{\r\n\s\s\s\s\s\s\s\screateFlags\s=\s0;\r\n\s\s\s\s}\selse\sif\s(applType\s==\sAPPL_DOS)\s{\r\n\s\s\s\s/*\r\n\s\s\s\s\s*\sUnder\sNT,\s16-bit\sDOS\sapplications\swill\snot\srun\sunless\sthey\scan\r\n\s\s\s\s\s*\sbe\sattached\sto\sa\sconsole.\sIf\swe\sare\srunning\swithout\sa\sconsole,\r\n\s\s\s\s\s*\srun\sthe\s16-bit\sprogram\sas\san\snormal\sprocess\sinside\sof\sa\shidden\r\n\s\s\s\s\s*\sconsole\sapplication,\sand\sthen\srun\sthat\shidden\sconsole\sas\sa\r\n\s\s\s\s\s*\sdetached\sprocess.\r\n\s\s\s\s\s*/\r\n\r\n\s\s\s\s\s\sstartInfo.wShowWindow\s=\sSW_HIDE;\r\n\s\s\s\s\s\sstartInfo.dwFlags\s|=\sSTARTF_USESHOWWINDOW;\r\n\s\s\s\s\s\screateFlags\s=\sCREATE_NEW_CONSOLE;\r\n\s\s\s\s\s\sTclDStringAppendLiteral(&cmdLine,\s"cmd.exe\s/c");\r\n\s\s\s\s}\selse\s{\r\n\s\s\s\s\s\s\screateFlags\s=\sDETACHED_PROCESS;\r\n\s\s\s\s}
J login anonymous
J mimetype text/plain
K f91ab723f3dfbc0d2b720a70a1fa09eebfa1cde5
U anonymous
Z 4bc3deff30d5e74d8b72152be63acf4e