Practical Programming in Tcl & Tk, Third Edition By Brent B. Welch
Table of Contents
Chapter 9. Working with Files and Programs
Input/Output Command Summary
The following sections describe how to open, read, and write files. The basic model is that you open a file, read or write it, then close the file. Network sockets also use the commands described here. Socket programming is discussed in Chapter 17, and more advanced event-driven I/O is described in Chapter 16. Table 9-5 lists the basic commands associated with file I/O:
Table 9-5. Tcl commands used for file access.
open what?access? ?permissions?
Returns channel ID for a file or pipeline.
puts ?-nonewline? ?channel? string
Writes a string.
gets channel?varname?
Reads a line.
read channel?numBytes?
Reads numBytes bytes, or all data.
read -nonewline channel
Reads all bytes and discard the last \n.
tell channel
Returns the seek offset.
seek channel offset?origin?
Sets the seek offset. origin is one of start, current, or end.