如何在 tcl 中向 exec 添加可变数量的参数? [英] How to add a variable amount of arguments to exec in tcl?

查看:25
本文介绍了如何在 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 以动态/可变的方式实现这一点时,我遇到了麻烦.我这样做的方法是将我需要的所有-i filex"存储在某个变量 myvar 中(在循环中完成),然后将其作为参数传递给 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?

推荐答案

您可以使用 {*}eval.例如,请参阅这个问题.

You can use {*} or eval. See this question for example.

这篇关于如何在 tcl 中向 exec 添加可变数量的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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