0

Is it possible to extend the tcl birary dll to have the capabilities of expect?

I have a C program that executes the TCL scripts by using the tcl library tcl85.dll. It works perfectly fine.

Recently i tried to execute some expect sripts and it failed. I understand that tcl85.dll doesn't have the capability to understand the expect commands by its own and that it needs to be extended. This is the point where I am stuck. I have the expect library expect543.dll downloaded from the activesite, but i am not able to figure out how to extend it with the tcl85.dll?

Any help or guidance is really appreciated.

Thanks Sunil

4

2 回答 2

2

您必须停止仅从 DLL 的角度考虑 Tcl 和 Expect:Tcl DLL 和 Expect DLL 都实现了各自软件的核心功能,但并不完全独立:

  • Tcl 解释器依赖于一组(动态)从文件系统加载的库文件。这些文件包括(但不限于)编码文件、时区信息文件和所谓的“核心包”,例如http.
  • Expect 包,作为一个常规pkgIndex.tclTcl 包,依赖于至少一个特殊的“索引文件”(Tcl 的包加载器。

因此,要完成所有这些工作,您大致必须遵循以下清单:

  1. 确保您嵌入代码中的 Tcl 解释器已正确初始化,因此它能够加载外部包。

  2. 完整的Expect 包放入嵌入式解释器希望找到外部包的位置之一。

    请务必阅读thisthisthis以了解包装机器的工作原理以及特殊全局变量auto_path的初始化方式。

  3. 在你的程序中调用package require Expect那些需要 Expect 包来加载它的脚本。

或者,您可以在嵌入式解释器上执行对 Tcl C API 的适当调用以直接加载 Expect 包的 DLL,以便稍后您执行的脚本可以立即使用它。

另一种选择(对于初学者来说比较棘手)是使用所谓的“basekit”或“tclkit”——一个 Tcl 库,其中包含使用虚拟文件系统的某些 Tcl 包以便这些包可以在运行时从该 VFS 加载。这些 *kits 很酷,但掌握创建一个合适的工具包比仅仅嵌入一个“常规”解释器以及一个作为一组文件与主程序一起分发的常规包更难。


一个特别说明:我不确定 ActiveTcl™ 产品的许可证是否允许撕掉它的各个部分并在您的产品中使用它们。IANAL但我怀疑您可能违反了该许可的条款。为了安全起见,从源头构建 Tcl 和 Expect —— 这并不难。

于 2013-07-30T12:52:57.417 回答
0

基本上我们需要初始化expect解释器。一旦完成,TCL_Eval(.) 也会理解期望代码。

Tcl_Interp *interp = Tcl_CreateInterp();
Tcl_FindExecutable(argv[0]);

if (Tcl_Init(interp) == TCL_ERROR) {
    fprintf(stderr,"Tcl_Init failed: %s\n",Tcl_GetStringResult (interp));
    (void) exit(1);
}
    //Initializing the expect interpreter here
if (Expect_Init(interp) == TCL_ERROR) {
    fprintf(stderr,"Expect_Init failed: %s\n",Tcl_GetStringResult (interp));
    (void) exit(1);
}
 //this can now take expect scripts as well in the buffer
 Tcl_Eval(interp, buffer);
于 2013-08-07T02:23:51.670 回答