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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tcl help needed, probably very simple to you 1

Status
Not open for further replies.

kamilhus

Technical User
Jan 9, 2007
3
US
Hello everybody

I'm trying to run two tcl scripts in parallel in such a way that one of the tcl script executes the other. Besides, the process of one depends on the output file(trace) of the other and vice versa. I simplified the problem into very understandable procedures so that you guys can help me in this one and I'll implemented in my scenario.

The following procedures are written in different TCL scripts.

proc tcl1 { } {
exec tcl tcl2.tcl &
set ff [open out1.tr w]
puts $ff "procedure1 line1"
set in1 [open "out2.tr" r]
gets $in1 line
puts $ff "1 $line"
close $in1
close $ff
}
tcl1

proc tcl2 { } {
set ff [open out2.tr w]
puts $ff "procedure2 line1"
set in1 [open "out1.tr" r]
gets $in1 line
puts $ff "1 $line"
close $in1
close $ff
}
tcl2

The aim of these two processes is that at the beginning, procedure 1 writes a line "procedure1 line1" on a file out1.tr. And Procedure 2 writes a line ""procedure2 line1" on file out2.tr. Then procedure1 reads the first line in out2.tr and writes it on the second line of its file out1.tr. Procedure 2 reads the first line in out1.tr and writes it on the second line of out2.tr. The intended outputs would be:
in out1.tr:
procedure1 line1
procedure2 line1

in out2.tr:
procedure2 line1
procedure1 line1

The procedure that I gave wouldn't run simply because the first line outputs are not ready by the time one wants to read the other. Can you help me with a mechanism that can force the procedures to wait for an output?

Thanks a lot,
Kamil
 
To force tcl1 one to wait for tcl2 to finish; don't put exec tcl2 in the background. Also, you need to close out1.tr before tcl2 can read it. This seems to work for me:

proc tcl1 { } {
set out1 [open out1.tr w]
puts $out1 "procedure1 line1"
close $out1
exec tclsh tcl2.tcl
set in2 [open "out2.tr" r]
gets $in2 line
set out1 [open out1.tr a]
puts $out1 "$line"
close $out1
close $in2
}
tcl1
proc tcl2 { } {
set out2 [open out2.tr w]
puts $out2 "procedure2 line1"
set in1 [open "out1.tr" r]
gets $in1 line
puts $out2 "$line"
close $out2
close $in1
}
tcl2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top