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!

hi all, if I want to save my output 2

Status
Not open for further replies.

RajVerma

Programmer
Jun 11, 2003
62
DE
hi all, if I want to save my output file in a format that can be read by a widows machine directly, without any manual conversion, what shud I do?
thanq,
Raj.
 
Code:
  set fp [open $myfile a]
  fconfigure $fp -translation binary
  puts -nonewline "$mystring\r\n"
  close $fp
This code insures that the proper end of line is written to the file.

HTH

ulis
 
Actually, ulis, a better way is to use the fconfigure command to explicitly tell Tcl what end-of-line sequence to use. The fconfigure -translation option determines how end-of-line sequences are handled, both for input and output. The default is "auto" -- Tcl automatically handles any end-of-line sequence as it reads, even if it changes while reading the channel; the proper output sequence is determined automatically based on the platform on which the script is executing.

However, you can explicity set the handling by assigning a new value to fconfigure -translation. If you assign a single value, it affects both reading and writing on the channel. But you can also provide a 2-element list to specify different handling for reading and writing.

So, to configure a channel to handle end-of-line conversion automatically on input, but to always write out carriage return-linefeed (\r\n) combinations on output (the Windows standard), you could do this:

Code:
set fid [open myfile.txt a+]
fconfigure $fid -translation {auto crlf}
puts $fid "Here's a line"
puts $fid "Here's another"

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top