<i>auto_execok uses cmd in preference to cmd.exe despite path order (windows)</i>.
by
.
D 2023-11-06T07:00:40.747
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-plain
J comment init.tcl's\sauto_execok\sfunction\shas\sfor\ssome\stime\ssince\s8.57\slooked\sfor\sexecutable\sfiles\swith\sempty\sextensions\sfirst.\s\r\nSome\stools\ssuch\sas\smsys2\sprovide\svarious\sshims/scripts\snamed\slike\stheir\sMS\scounterparts\seither\swith\sor\swithout\sa\s.exe\sextension.\r\n\r\nWith\sc:\\windows\\system32\searliest\sin\sthe\spath\s-\sone\swould\sexpect\sthat\styping\scmd\sat\sa\sprompt\swould\spreferentially\sfind\sthe\snormal\sc:\\windows\\system32\\cmd.exe\s-\sor\suse\sthe\s$env(COMSPEC)\svalue.\s\s\sFor\sshell\sbuiltins\sas\sdefined\sin\sthe\sauto_execok\sfunction\ssuch\sas\s'echo'\s-\sthe\scorrect\scmd.exe\sis\sused\s(from\sCOMPSPEC).\r\n\r\nHowever\s-\sin\sthe\spresence\sof\ssome\sother\sfile\snamed\scmd\sin\sthe\spath\s-\sjust\styping\scmd\sin\sthe\sshell\sloads\sthat\sother\spath\sinto\sthe\s::auto_execs\sarray.\r\n\r\n\r\nThis\scan\sbe\sworked\saround\sby\styping\scmd.exe\sinstead\sof\sjust\scmd,\sbut\sit\sis\ssurprising,\sand\sI'm\swondering\sif\sat\sleast\sfor\scmd\s-\sthis\scould\sspecifically\suse\sthe\sCOMSPEC\svalue\s-\sas\sthis\sis\swhat\sis\schosen\sfor\sthe\sbuiltins,\sand\sI\scan't\sthink\sof\sa\scircumstance\swhere\scmd\sshould\spoint\sto\sa\sdifferent\slocation\sthan\sits\sbuiltins.\r\n\r\nThe\spotential\sremains\sfor\sother\sprograms\sto\sbe\sselected\sin\san\sorder\sbased\son\sextension\sthat\sdoesn't\sfollow\sthe\sorder\slisted\sin\sPATH\s-\spresumably(?)\sit\sis\sdone\sthis\sway\sfor\sperformance\sso\sthat\sthe\sentire\sset\sof\sPATH\sdirs\sisn't\ssearched\sfor\seach\sextension\s-\sbut\sI\sdo\salso\swonder\sat\sthe\sreason\sfor\s'no\sextension'\sbeing\sahead\sof\s.exe\r\n\r\nCurrent\ssearch\sorder\sis\s{foreach\sextension\s{foreach\spath\s...}}\r\n\r\nGenerally\son\swindows\sone\sexpects\sthe\searlier\sentries\sin\sthe\spath\sto\sbe\srespected\s\s-\sbut\sTcl\son\swindows\shas\soperated\sin\sthis\sway\sfor\ssome\stime.\r\n\r\n\r\nMight\sit\sbe\sworthwhile\sdoing\sa\spre-scan\sfor\sall\sextensions\sin\sthe\sdirname\sof\s$::env(COMPSPEC)\s(usually\ssomething\slike\sc:\\windows\\system32),\sthen,\snoting\sthe\sposition\sof\sthat\sfolder\sin\sthe\sPATH\s(or\sgiving\slowest\spref\sif\snot\spresent),\sonly\sreplace\sit\sin\sauto_execs\sif\ssomething\swas\sfound\searlier\sin\sthe\sPATH?\r\n\r\nThat\sproposal\sgives\sthe\sfolder\sof\sCOMSPEC\sa\sspecial\sprivilege\s-\swhich\sis\sa\sbit\sugly.\r\n\r\nRather\sthan\sthat,\smy\spreference\swould\sbe\sto\sreverse\sthe\sthe\sloop\snesting\sand\ssearch\sonce\sthrough\sthe\sfolders\sbut\scheck\seach\sof\sthe\s5\sextensions\s-\sas\sthis\sis\sthe\sleast\ssurprising\sin\sterms\sof\show\susers\shave\stheir\sPATH\sconfigured\s-\sbut\sI\sdon't\sknow\swhy\sthe\scurrent\sordering\swas\schosen.\r\n\r\nSome\svery\srough\stesting..\sI\shave\sa\sbit\sover\s100\sfolders\sin\smy\sPATH\s-\swhich\sI\ssuspect\sis\ssomewhat\shigher\sthan\smost.\s\r\n\r\nDoing\sa\stcl\sglob\sfor\sthe\s5\sextensions\s(with\sa\sspecific\sfilename)\sin\sone\scall\sfor\sa\sfolder\swith\ssay\s50\sfiles\s-\stakes\sless\sthan\s1ms\s\s\s\r\nDoing\sthe\ssame\son\sa\slarge\sfolder\ssuch\sas\sc:\\windows\\system32\s(contains\saround\s5k\sfiles)\stakes\sless\sthan\s3ms\s\r\n\r\nboth\sthese\srough\stests\swere\sfor\snon-existent\snames\se.g\r\nglob\s-nocomplain\s-dir\s$d\s-tail\sflubber\sflubber.exe\sflubber.cmd\s...\r\n\r\nA\ssingle\sglob\slike\sthis\sis\sa\sbit\sfaster\sthan\stesting\sfile\sexists\sfor\seach\sone.\r\n\r\nWith\smy\schanges\sbelow\s\s-\sentering\sa\snon\sexistent\scommand\sreturns\sabout\s4x\sfaster\s(noticeable\sin\sinteractive\sshell)\sand\sthe\sselection\srespects\sthe\sPATH\sorder.\sPlease\sreview\sand\sconsider.\r\n\r\n\r\n\s\s\s\sset\slookfor\s[lmap\sext\s$execExtensions\s{string\scat\s${name}\s${ext}}]\r\n\s\s\s\sforeach\sdir\s[split\s$path\s{;}]\s{\r\n\s\s\s\s\s\s\s\s#\sSkip\salready\schecked\sdirectories\r\n\s\s\s\s\s\s\s\sif\s{[info\sexists\schecked($dir)]\s||\s($dir\seq\s"")}\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\scontinue\r\n\s\s\s\s\s\s\s\s}\r\n\s\s\s\s\s\s\s\sset\schecked($dir)\s{}\r\n\s\s\s\s\s\s\s\sforeach\smatch\s\s[glob\s-nocomplain\s-dir\s$dir\s-tail\s{*}$lookfor]\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\sset\sfile\s[file\sjoin\s$dir\s$match]\r\n\s\s\s\s\s\s\s\s\s\s\s\sif\s{[file\sexists\s$file]\s&&\s![file\sisdirectory\s$file]}\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sreturn\s[set\sauto_execs($name)\s[list\s$file]]\r\n\s\s\s\s\s\s\s\s\s\s\s\s}\r\n\s\s\s\s\s\s\s\s}\r\n\s\s\s\s}\r\n\r\n\s\s\s\sif\s0\s{\r\n\s\s\s\s\s\s\s\sforeach\sext\s$execExtensions\s{\r\n\s\s\s\s\s\s\s\sunset\s-nocomplain\schecked\r\n\s\s\s\s\s\s\s\sforeach\sdir\s[split\s$path\s{;}]\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\s#\sSkip\salready\schecked\sdirectories\r\n\s\s\s\s\s\s\s\s\s\s\s\sif\s{[info\sexists\schecked($dir)]\s||\s($dir\seq\s"")}\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\scontinue\r\n\s\s\s\s\s\s\s\s\s\s\s\s}\r\n\s\s\s\s\s\s\s\s\s\s\s\sset\schecked($dir)\s{}\r\n\s\s\s\s\s\s\s\s\s\s\s\sset\sfile\s[file\sjoin\s$dir\s${name}${ext}]\r\n\s\s\s\s\s\s\s\s\s\s\s\sif\s{[file\sexists\s$file]\s&&\s![file\sisdirectory\s$file]}\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\sreturn\s[set\sauto_execs($name)\s[list\s$file]]\r\n\s\s\s\s\s\s\s\s\s\s\s\s}\r\n\s\s\s\s\s\s\s\s}\r\n\s\s\s\s\s\s\s\s}\r\n\s\s\s\s}
J foundin 8.6+
J is_private 0
J login juliannoble2
J priority 5\sMedium
J private_contact 957fdfcd8744611e3fe1f4896c7538b1d9bf47b2
J resolution None
J severity Minor
J status Open
J submitter juliannoble2
J subsystem 38.\sInit\s-\sLibrary\s-\sAutoload
J title auto_execok\suses\scmd\sin\spreference\sto\scmd.exe\sdespite\spath\sorder\s(windows)
J type Bug
K 596936dd2d55ba70dcdc980b9f58b3dccf248605
U juliannoble2
Z 6fb4f247e5e040876d56f2599666a752