如何在tcl中向exec添加可变数量的参数? [英] How to add a variable amount of arguments to exec in tcl?
问题描述
我需要通过tcl脚本执行外部程序。为此,我使用 exec
命令。对于使用这个外部程序,我需要输入一个可变量的文件。如果我直接从cmd窗口打了这个程序,那就是这样的:
C:\> myprogram -i file1 -i file2 -i file3(等等)
但是,当尝试实现这个在动态/可变的方式通过tcl我陷入麻烦。我所做的是通过将一些变量myvar存储在所有的 -i filex
中,我需要(在循环中完成),然后将其作为参数传递给 exec
命令。它看起来像:
exec myprogram $ myvar
这样做显然会造成一些问题,因为这个myprogram不能看到myvar。我猜想有一些隐藏的终结符或一些不同类型的参数的冲突,使得exec命令看到只是myprogram。
所以,我的问题是,有没有人知道如何将变量参数插入到调用 exec
?
您可以使用 {*} 或 eval 。请参阅此问题。
I've been working with TCL for some time now, and I have spent a long time trying to do the following (it seems easy and I think it should be, but I can't get it right):
I need to execute an external program by means of a tcl script. For that, I use the exec
command. For using this external program, I need to input a variable amount of files. If I called this program straight from a cmd window, it would be something like:
C:\>myprogram -i file1 -i file2 -i file3 (etc., etc.)
However, when trying to implement this in a dynamic/variable way through tcl I get into trouble. The way I do it is by storing in some variable myvar all the "-i filex
" I need (done in a loop), and then pass that as a parameter to the exec
command. It would look something like:
exec myprogram $myvar
Doing that apparently creates some issues, because this myprogram fails to "see" myvar. I'm guessing that there is some sort of hidden terminator or some clash of different types of arguments that makes that in the end the exec command "sees" only myprogram.
So, my question is, does anyone know how to insert variable arguments into a call to exec
?
You can use {*} or eval. See this question for example.
这篇关于如何在tcl中向exec添加可变数量的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!