如何添加一个变量量论点TCL给exec? [英] How to add a variable amount of arguments to exec in tcl?

查看:194
本文介绍了如何添加一个变量量论点TCL给exec?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直与TCL工作了一段时间,现在,我已经花了很长时间试图做以下(这似乎很容易,我认为这是应该的,但我不能得到它的权利):

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):

我需要一个Tcl脚本来执行外部程序。对于这一点,我用的是 EXEC 命令。对于使用这个外部的程序,我需要输入文件数量可变的。如果我从一个cmd窗口直接调用该程序时,它会是这样的:

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.)

但是,试图通过TCL实现这个以动态/可变的方式,当我陷入困境。我这样做的方式是通过在一些变量myvar的存储所有的 -i FILEX 我需要(在一个循环中完成),然后传递作为参数传递给 EXEC 命令。它看起来是这样的:

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

这样做,显然造成一些问题,因为这myprogram无法看到MYVAR。我猜有某种隐藏的终结者或不同类型的参数的一些冲突,使得这到底exec命令看到只有myprogram。

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.

所以,我的问题是,没有人知道如何插入变量参数到调用 EXEC

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆