Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get one tcl script to to kick another passing it arguments

Status
Not open for further replies.

hija

Programmer
Oct 30, 2002
16
AU
How do I get one tcl program to invoke a second tcl program passing the the program some variable values generated in the first.
This might seem a strange thing to do.
But the intent is to be able to write testdriver scripts (the first program) to check the performance of the second program.?


Hija
 
I think Expect already does what you're trying to reproduce but I don't know any more about Expect than that.

You can have the 2nd script look for command line arguments (if you have to call it in a separate shell). Then, invoke it from the first by "exec wish83.exe arg1 arg2 .." Bob Rashkin
rrashkin@csc.com
 
I forgot to include the second script:
&quot;exec wish83.exe <2nd script> arg1 arg2 ..&quot; Bob Rashkin
rrashkin@csc.com
 
Thanks Bob I'll give it a try
hija
 
One can create custom TCL libraries in the eMatrix Business tool and &quot;utLoad&quot; them into &quot;driver&quot; programs as suggested by this indicent.

This gives a consistent and reusible interface to common areas of functionality.

One the libraries that I have created and use often is:
SharedServices.lib.tcl

(this is sort of a TCL enhanced version of 'C' stdio.h)

The above contains all of my standardized IO type functions for processing errors, messages, etc. plus my IPM services (persistent InterProcess Messaging services).

The above library becomes a baseline for all 'higher' level programs to load and use these standard &quot;custom&quot; commands.

The structure of a library is:

proc x {args} {
...}

proc y {type name rev} {
...}

proc z {a b {c &quot;default&quot;}} {
...}

etc.

Note that there is NO &quot;tcl;&quot; statement,and that the &quot;utLoad&quot; function is not defined here, but in the higher level program (note: you can use [info commands utLoad] to test and see if the command has already been created and conditionally create it if not). Also, no &quot;exit&quot; statement is at the bottom. Remember that &quot;utLoad&quot; does an:

eval [mql print prog NAME select code dump]

inline in your program, so that the above procs exist in your program code at runtime as if you had copied the code in manually. Normally, there is no directly executible statements in the library, only proc defenitions. (note: I've created a &quot;RulebaseRegistry&quot; library that does execute the search for and loading of all rulesets from Rulebase BOs at runtime. Same is true of some cool stuff I've done with wizard frameworks, but normally this is not the case).

Hence, your &quot;driver&quot; program will:

tcl
eval [utLoad myLibrary.tcl]
set a [x $argList]
exit 0

to run one or all of the needed standardized procs as defined in the library.

Note that parameter values are passed from the &quot;driver&quot; program as $arglist and recieved by the proc as:

proc myProc {arg1 arg2 ... argn} {...

Also note that there is a special TCL procedure argument called &quot;arg&quot; that allows you to pass an unspecified number of parameters to a PROC and sort them out at the other end. I have used a strategy for posting parameters as name/value parts rather than ordered arguments, and calling an &quot;interface&quot; procedure (sort of like a &quot;property&quot; subroutine in MSVisual Basic) that parses the supplied parameters, supplies all other needed arguments per defaults, and structures the arguments to call the &quot;real&quot; PROCedure. This is one strategy to implement &quot;public&quot; and &quot;private&quot; PROCedures in TCL (I futher use namespaces to create an &quot;object&quot; at runtime, and have all &quot;object methods&quot; exist in the namespace as &quot;private&quot; while all &quot;interface&quot; or &quot;public&quot; routines exist outside the namespace as &quot;properties&quot; to the TCL object. IE:

namespace eval $ObjName {
variable something

proc myPrivateMethod {x y z}{
...
set something $y
...}
}; #~endObj

proc myPublicProperty {args} {
foreach arg $args {
set param [lindex [split $arg =] 0]
set value [lindex [split $arg =] 1]
switch $param {
...
}
# if PARAM was y
...
set x $defaultX
set z $defaultZ
set retval [\$ObjName\:\:myPrivateMethod \$x \$y \$z]
}
return $retval
}

set retval [myPublicProperty &quot;y=7&quot;]
exit $retval

For passing arguments in Matrix TCL is done by:

General program::
sending:
exec prog MyProg Drawing 1234 A
recieving:
set myType [mql get env 1]
set myName [mql get env 2]
set myRev [mql get env 3]

Method program::
sending:
mql execute bus ...
(not applicable, all params set by system)
recieving:
set myType [mql get env TYPE]
set myName [mql get env NAME]
set myRev [mql get env REVISION]

Trigger program:
sending:
(parameters configured in the trigger dialog, myVAR)
recieving:
set myType [mql get env TYPE]
set myName [mql get env NAME]
set myRev [mql get env REVISION]
set myVAR [mql get env 1]

Wizard program (between frame prologue/epilogue, wiz CODE)
sending:
mql set env myVAR &quot;this is the value&quot;
recieving:
set myNewVar [mql get env myVAR]

Hope this helps!

Best regards,

John Lopez
mailto:developer4matrix@hotmail.com
P.O. Box 290
Deerfield, Ohio, USA
44411
330.947.3800 John Lopez
Enterprise PDM & Integration Consulting
Development for MatrixOne PDM Systems
johnlopez2000@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top