Reputation: 3
Description
Current result
My scripts "name1" and "name2" are executing in the different tclsh windows As a result, the "name2" is not familiar with the variables of the "name1"
Expected result
"name1" and "name2" are executed in the same tclsh window
Comment
I tried to use these commands but I don't know its syntax in the VBScript
Tcl_Create tclHandler, TCL_Eval Status, tclHandler,
It would be nice to have an example how to use these commands in the VBScript, or any other
Thanks
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:\RunTCL\name1.tcl"
crt.Sleep 10000 ' or any VBScript commands
shell.run "tclsh e:\RunTCL\name2.tcl"
End Sub
package req SpirentTestCenter
set hProject [stc::create project]
set hTxPort [stc::create port -under $hProject -location //192.168.0.243/10/17 -useDefaultHost False]
set hRxPort [stc::create port -under $hProject -location //192.168.0.243/10/25 -useDefaultHost False]
New code with tcl84.dll and its commands "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:\Tcl\bin\tcl84.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]"
As a result, I see this message: Error:ActiveX component can't create object 'c:\tcl\bin\tcl84.dll'
I can use 2 options:
But nobody is working
Good news, it starts to work, however, I would prefer to execute separate TCL files by API
shell.run "tclsh"
crt.Sleep 10000
shell.AppActivate "tclsh"
shell.SendKeys("TCL command")
Upvotes: 0
Views: 1097
Reputation: 33203
tcl84.dll
is not something that provides a COM class. You cannot create a Tcl interpreter using the VBScript CreateObject
call like this. VBScript does not have a mechanism to access exported functions directly from a DLL so you cannot run your Tcl code from VBScript except by executing a tclsh
or wish
process.
Each time you execute tclsh.exe scriptfile
you are creating a new child process. It will run your script but when it exits the process is terminated and everything about it is lost unless you read the standard output or wrote information to a file to preserve it. So running a second script will of course have no knowledge of the first script.
One way to run two tcl scripts together is to create a script that uses the tcl source
command to load both scripts into a single interpreter. Another method might be to read the output of the first script, parse out the values you need and pass these as command line arguments to the second. Or you could have the first script write a file of tcl commands that when sourced in the second process will update the variables you require.
Your final example is creating a single process and communicating via emulated keystrokes. This is really slow and error prone. There is a winsend package that can let you send messages to tcl interpreters from vbscript. There might be some others as part of TWAPI
that can let you register the interpreter for external access.
Upvotes: 0