exec quotes its arguments automatically which can lead to problems when unescaped quotes need to be inserted in a commandline. ''This sounds like a misinterpretation of what [exec] does. There is no quoting going on, because [exec] is directly constructing the [argv] array of the program being called!'' ---- If arguments contain spaces exec will quote the argument before passing it on (some testing shows that it is actually a bit more involved than this). So {c:\Documents and Settings} will be changed to "c:\Documents and Settings". However, sometimes you want to force this quoting of an argument. One example I have encountered is when passing parameters to a batch file that contain comma's: test.bat a,b will call test.bat with two parameters a and b. This can be very useful, but leads to problems when you want to send a,b as one parameter. The solution is to quote the a,b test.bat "a,b" If we want to call this batchfile from Tcl, the first idea would be to use exec test.bat {"a,b"} but here exec will quote this to: test.bat \"a,b\" Instead the << argument to exec can be used in combination with cmd.exe. << will pipe the remaining args to the stdin of the program. So exec cmd << "test.bat \"a,b\"\n" ; # note the trailing \n will lead to the desired effect. -- [MJ] [RS] Very cool - I had exactly that problem yesterday! To prevent forgetting the \n, one might wrap it like this: proc do cmd {exec cmd << $cmd\n} [MJ] I have noticed before that there seems to be some sort of problem synchronization on the Tcl chat. Yesterday (2006-08-26) was apparently exec day ;-) [MJ] The main issue with exec quoting seems to be that the automatic quoting exec applies (even though it is correct and convenient most times) sometimes gets in the way. It would therefore be nice if exec allowed a flag that disables all automatic quoting to allow the programmer to specify the exact quoting in case exec gets it wrong. This would allow a solution like: exec -noquoting {test.bat "a,b"} This will also make use of auto_execok without eval possible (although in 8.5 [{expand}] solves this in different way): exec -noquoting "[auto_execok start] http://www.tcl.tk" ; # 8.4.13 exec {expand}[auto_execok start] "http://www.tcl.tk" ; # 8.5 This new flag will only lead to problems with older scripts if a command named -noquoting exists which seems unlikely. [RS] Another point that ''exec -noquoting'' should handle is to take < and > literal, not as redirections, e.g. exec echo "" [MJ] Idealiter -noquoting would refrain from interpreting any special characters such as " < << 2> etc. So the tag case should be handled correctly eg: % exec echo "" couldn't read file "starttag>": no such file or directory % exec -noquoting echo "" % [MJ] You can download a patch on 8.5a3 from [http://marknet.tk/downloads/exec.patch] that adds a -noquote option to exec. Only quoting of " is disabled. Disabling handling of < | etc. is more complicated.