如何在同一个tclsh窗口中运行多个TCL脚本



描述

  1. 我使用VBScript
  2. 在VBScript中,我将我的第一个TCL脚本称为"name1"
  3. 脚本"name1"完成后,我继续使用VBScript
  4. 在几个VBScript函数之后,我将我的第二个TCL脚本称为"name2",这个脚本是脚本"name1"的子进程。脚本"name2"必须使用脚本"name1"中的所有变量

当前结果

我的脚本"name1"one_answers"name2"正在不同的tclsh窗口中执行因此,"name2"不熟悉"name1"的变量

预期结果

"name1"one_answers"name2"在同一tclsh窗口中执行

评论

我试着使用这些命令,但我不知道它在VBScript 中的语法

创建tclHandler,TCL_Eval状态、tclHandler、

有一个如何在VBScript或任何其他中使用这些命令的例子会很好

感谢

VBScript:

#$language = "VBScript"
#$interface = "1.0"
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
crt.Screen.Synchronous = True
Sub Main
 dim shell
   set shell=createobject("wscript.shell")
   shell.run "tclsh e:RunTCLname1.tcl"
   crt.Sleep 10000 ' or any VBScript commands
   shell.run "tclsh e:RunTCLname2.tcl" 

结束子

名称1.cl

软件包需求SpirentTestCenter

设置hProject[stc::创建项目]

set hTxPort[stc::create port-under$hProject-location//192.168.0.243/10/17-useDefaultHost False]

名称2.tcl

set hRxPort[stc::create port-under$hProject-location//192.168.0.243/10/25-useDefaultHost False]

带有tcl84.dll及其命令"TCL_Create tclHandler"的新代码:

#$language = "VBScript"
#$interface = "1.0"
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
crt.Screen.Synchronous = True
Sub Main
Dim wscriptTCL 
tclHandler = 0
set wscriptTCL =CreateObject("C:Tclbintcl84.dll")
TCL_Create tclHandler, wscriptTCL, 1
puts "Importing STC API"
TCL_Eval Status, tclHandler, "package req SpirentTestCenter"
puts "Creating API objects set"
TCL_Eval Status, tclHandler, "set hProject [stc::create project]"
puts "Connecting to STC ports" 
TCL_Eval Status, tclHandler, "set hTxPort [stc::create port -under $hProject -location //10.110.10.243/8/9 -useDefaultHost False]"
src.Sleep 100000
TCL_Eval Status, tclHandler, "set hRxPort [stc::create port -under $hProject -location //10.110.10.243/8/10 -useDefaultHost False]"

因此,我看到了以下消息:错误:ActiveX组件无法创建对象"c:\tcl\bin\tcl84.dll"

我可以使用2个选项:

  1. 从我的VB脚本调用tcl文件
  2. 通过dll从VB脚本调用tcl命令

但没有人在使用

好消息,它开始工作,但是,我更喜欢通过API执行单独的TCL文件

  shell.run "tclsh"
  crt.Sleep 10000
  shell.AppActivate "tclsh"
  shell.SendKeys("TCL command")

tcl84.dll不是提供COM类的东西。不能像这样使用VBScript CreateObject调用创建Tcl解释器。VBScript没有直接从DLL访问导出函数的机制,因此除非执行tclshwish进程,否则无法从VBScript运行Tcl代码。

每次执行tclsh.exe scriptfile时,都会创建一个新的子进程。它会运行你的脚本,但当它退出时,进程就会终止,除非你读取标准输出或将信息写入文件以保存它,否则它的所有内容都会丢失。因此,运行第二个脚本当然对第一个脚本一无所知。

同时运行两个tcl脚本的一种方法是创建一个脚本,该脚本使用tcl source命令将两个脚本加载到单个解释器中。另一种方法可能是读取第一个脚本的输出,解析出所需的值,并将这些值作为命令行参数传递给第二个脚本。或者,您可以让第一个脚本编写一个tcl命令文件,当在第二个进程中获取该文件时,它将更新您需要的变量。

最后一个例子是创建一个进程,并通过模拟按键进行通信。这真的很慢而且容易出错。有一个winsend包可以让您从vbscript向tcl解释器发送消息。作为TWAPI的一部分,可能还有一些其他程序可以让您注册解释器以进行外部访问。

最新更新