Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Running BASH script from TCL

1,511 views
Skip to first unread message

adic...@gmail.com

unread,
Aug 19, 2008, 8:01:15 AM8/19/08
to
Hi,

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

unread,
Aug 19, 2008, 8:09:40 AM8/19/08
to
Does my_app/the tcl application actually exit? If not your exec
blocks until they do.


--
Ron Fox
NSCL
Michigan State University
East Lansing, MI 48824-1321

adic...@gmail.com

unread,
Aug 19, 2008, 8:26:55 AM8/19/08
to
> > Adi (adich...@gmail.com)

>
> --
> Ron Fox
> NSCL
> Michigan State University
> East Lansing, MI 48824-1321- Hide quoted text -
>
> - Show quoted text -

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 :)

Glenn Jackman

unread,
Aug 19, 2008, 10:32:52 AM8/19/08
to
At 2008-08-19 08:01AM, "adic...@gmail.com" wrote:
> Hi,
>
> 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
> }
> }

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

adic...@gmail.com

unread,
Aug 19, 2008, 11:04:24 AM8/19/08
to
On Aug 19, 7:32 pm, Glenn Jackman <gle...@ncf.ca> wrote:
>     Write a wise saying and your name will live forever. -- Anonymous- Hide quoted text -

>
> - Show quoted text -

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...

Cameron Laird

unread,
Aug 19, 2008, 10:47:37 AM8/19/08
to
In article <b81cbef5-e75b-4388...@p10g2000prf.googlegroups.com>,

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.

adic...@gmail.com

unread,
Aug 19, 2008, 11:28:00 AM8/19/08
to
On Aug 19, 7:47 pm, cla...@lairds.us (Cameron Laird) wrote:
> In article <b81cbef5-e75b-4388-b318-6ad702a7e...@p10g2000prf.googlegroups.com>,
> focus narrowly on [exec]'s process control.- Hide quoted text -

>
> - Show quoted text -
Hi,

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

adic...@gmail.com

unread,
Aug 20, 2008, 3:33:03 AM8/20/08
to
> Aditya- Hide quoted text -

>
> - Show quoted text -

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

Ron Fox

unread,
Aug 20, 2008, 7:10:33 AM8/20/08
to
I said exit not exists.
^^^^ ^^^^^^^
If your application runs, but never exits your exec will block.

Glenn Jackman

unread,
Aug 20, 2008, 9:05:16 AM8/20/08
to
At 2008-08-20 03:33AM, "adic...@gmail.com" wrote:
> 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]
> }
> }

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]} {
...

adic...@gmail.com

unread,
Aug 21, 2008, 12:55:56 AM8/21/08
to
On Aug 20, 6:05 pm, Glenn Jackman <gle...@ncf.ca> wrote:

Thanks Glenn. I'll keep this in mind. :)

0 new messages