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!

file io read tcl script 1

Status
Not open for further replies.

5a5a

Programmer
Aug 28, 2007
4
CA
Hi
I am trying to ivoke one tcl from another tcl file

I have two tcl files called ( compile.tcl, sim.tcl)

and one text file list.txt

Script:
#compile.tcl
#!/usr/bin/tcl

set dir "../bin"
set f [open $dir/list.txt r]

while {1} {
gets $f line
puts "SIMULATION STARTS "
exec tclsh $dir/sim.tcl $line
if {[eof $f]} {
close $f
break
}

}

Error here ,I am not able to execute the sim.tcl

Please suggest some ideas


 
I'm not sure why this should be but I have encountered the situation where the interior of a while loop behaves like a proc. That is, the scope is different. Try specifying ../bin/sim.tcl instead of $dir/sim.tcl and see what happens.

_________________
Bob Rashkin
 
Hi bong
Thanks,
I have tried with ../bin/sim.tcl instead of $dir/sim.tcl
its again strucked with same problem
 
One more point for your information

Using exec:

If i am using exec command it is hanging

exec tclsh ../bin/sim.tcl $line

Using Source

source ../bin/sim.tcl $line

If I am using the source command

Please suggest some ideas

Error:wrong #args :should be source "filename

 
First of all, the source issue:
source does not invoke a proc; it only loads the script in the memory of the executing interpreter. So now it's time to ask what the script, sim.tcl looks like. I assume it's a stand-alone script. That is, if you ran it by itself, it does something. The presence of the $line argument implies that you are reading command line arguments inside the code to set a variable. This is not going to work with source as there is no command line per se. However, when you use source, the loaded script has knowledge of all the variables that are currently set, specifically $line. When I use command line arguments, I usually set the variable explicitly, then check for command line arguments ($argc>0) and then override the variable with the argument passed in. If that's what you do in sim.tcl, you can source sim.tcl and set whatever variable you need to to $line.

Now, as far as invoking the script with exec, your syntax is fine. That leads me to suspect that maybe sim.tcl isn't handling command line arguments the way you think it is. I'd have to see some of your code to go further.

_________________
Bob Rashkin
 
Many Thanks Bong ( Pls Keep going)

Sim.tcl wil take the arguments from the text file ( which contains test ids)
( so my text file contains list of testids like test1 ,test2,test3,test4.......)

sim.tcl test1
sim.tcl test2

so that i have used file io in tcl

sim.tcl $line


inorder to execute this
 
Now it's starting to sound like sim.tcl is a proc, as in
Code:
proc abc {var} {
}
If that's the case, you can't invoke it directly in the shell, you have to call it. Can you post the code (if it's too long, maybe just the relavant part)?

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top