Context: Windows 7, ActiveState Tcl 8.6.1

% info tclversion
8.6
% info patchlevel
8.6.1

I have a C# console mode app called SETCFG.EXE. It's on the path in C:\BIN.

% set project corp
corp
% set method Recent
Recent
% exec -- [list c:/bin/setcfg.exe bobat.cfg inserter.${project}.Method $method]
couldn't execute "c:\bin\setcfg.exe bobat.cfg inserter.corp.Method Recent": no such file or directory

Now it could be that I'm not specifying the tcl code correctly -- it has been many years since the last encounter -- so I'll try execing a string

% exec -- "c:/bin/setcfg.exe bobat.cfg inserter.${project}.Method $method"
couldn't execute "c:\bin\setcfg.exe bobat.cfg inserter.corp.Method Recent": no such file or directory

Hmmm ... maybe I need to put the program first and the parameters second ...

% exec -- "c:/bin/setcfg.exe" "bobat.cfg inserter.${project}.Method $method"
Syntax:
        c:\bin\setcfg.exe cfg sym val
child process exited abnormally

Parameters in a list?

% exec -- "c:/bin/setcfg.exe" [list bobat.cfg inserter.${project}.Method $method]
Syntax:
        c:\bin\setcfg.exe cfg sym val
child process exited abnormally

So what am I not doing right? I've tried a few possibilities. Are there yet more?

有帮助吗?

解决方案

You need to specify several args to exec, not a single arg. You want

exec -- c:/bin/setcfg.exe  bobat.cfg  inserter.${project}.Method  $method

Sometimes, you'll see code that constructs the command as a list. In that case, you will use the "splat" operator to expand the list into individual elements.

set command [list c:/bin/setcfg.exe bobat.cfg inserter.${project}.Method $method]
exec -- {*}$command

See the exec man page and the Tcl syntax page

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top