I've a TCL script which generates some more TCL scripts (e.g. scr1.tcl
to scr5.tcl).
I've an application (my_app.exe) which executes these generated TCL
script.
For doing this I've written the following code:
proc runScripts { } {
set tclScriptFileList [exec ls scr*.tcl]
set tclScriptFileCount [llength $tclScriptFileList]
set count 1
while { $count <= $tclScriptFileCount } {
set tclFileName "./scr$count.tcl"
exec my_app -tclFile $tclFileName
incr count
}
}
This procedure when called executes the appication for the first
script and then hangs. And hence I'm not able to execute all the
generated scripts one after the other.
Can you suggest some solution for this???
As a woraround, I wrote the same procedure in BASH script and it
executes well. But I'm not able to execute it from the TCL script.
Please advise on the same...
Thanks and Best Regards
Adi (adic...@gmail.com)
--
Ron Fox
NSCL
Michigan State University
East Lansing, MI 48824-1321
Thanks for the quick reply...
The application exists and it executes also. The application takes up
the TCL script and executes it.
After that the application exits and I was expecting the control to
return to the TCL procedure, but that doesn't happen.
Thanks again :)
In your bash script, did you execute my_app in the background?
How about:
proc runScripts {} {
foreach script [lsort -dictionary [glob scr*.tcl]] {
# launch my_app in the background
exec my_app -tclFile $script &
}
}
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
I don't want to execute the application in background. I want the
applications to be executed sequentially.
Hence the & would not work out here...
I assure you that, when my_app finishes, the controlling
Tcl resumes operation. I understand you have observations
that suggest otherwise. It's VERY likely that there's a
different and truer explanation, though.
Your Tcl is unidiomatic; eventually, we can help you rewrite
it to a more succinct and maintainable form. The issue for
now, though, does need to be the process control you describe.
If this were my problem, I'd divide-and-conquer my way to
success; that is, instead of staying stuck with a large program
that doesn't work, I'd start isolating "hot spots" to be sure
they're doing what I expect. You've said, for example, that
"[t]he application exists and it executes also"; does
puts Before.
exec my_app -tclFile $tclFileName
puts After.
do what you expect in isolation? Take it out of the look,
eliminate any questions about how many *.tcl-s there are, and
focus narrowly on [exec]'s process control.
Thanks for your response.
I'm using Komodo IDE for debugging the problem. In Komodo, when I do
single stepping, the control does not come to the next line after exec
command. I tried putting puts statement too and that also didn't work.
Also, getting the stuff out of the loop doesn't help at all.
In the Task Manager, I can not see the my_app running any longer, so
it has exited. Now the control is expected to come back to the TCL
application, but that doesn't haapen.
Any more ideas to fix this up are welcome.
As a workaround I've written a c-shell script for the same process and
the script works fine from the c-shell.
I'm running the c-shell script using:
exec csh execTCLScripts.csh
This executes the c-script, but the application my_app exits without
running the tcl script.
Any help on this would be also be well appritiated.
Thanks and Best Regards
Aditya
I was able to make it work using the following code:
foreach script_file [lsort -dictionary [glob scr*.tcl]] {
set pid [exec my_app.exe -tclFile $script_file & ]
set ps [exec ps]
while { [lsearch $ps $pid] != -1 } {
after 5000
set ps [exec ps]
}
}
I ran the my_app in the background and then keep checking the time
till which it's running. Once the application has finished running, I
ran it again using the next script file.
Thanks everyone for your help and suggestions.
Aditya
Note that the output of [exec] is a string, not a list. You may get
bitten in the future when you use list commands on a string, but more
particularly if you use string commands on a list.
You might want to use
while {[regexp "\\m$pid\\M" $ps]} {
...