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!

Redirect text to a file.

Status
Not open for further replies.

rbautch

Technical User
Sep 16, 2005
8
US
I'm very new to tcl. I would like to add a line to my script that writes a block of text to a log file with the date and time shown in the log entry. The entry in the log file would look something like: Sept 11 8:05pm Main Script Ran. Please help! Thanks in advance.
 
Let's say the log file exists; call it "log.txt". First you'll want to open it:
set fid [open log.txt w]

Then, at the appropriate moment, you'll want to get the current time in the right format:
set tnow [clock format [clock seconds] -format "%b %d %I:%M%P"]

Then put it out in the log file:
puts $fid "$tnow <your text>"

And it's good form to close the log file when you don't need it anymore:
close $fid

_________________
Bob Rashkin
rrashkin@csc.com
 
That's just what I was looking for. Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top