Name

open

open fileName [access] [permissions]

Open the specified file, device, or command pipeline using an access specifier (described in the following list). Return a channel identifier that can be used in subsequent I/O commands. FileName can be a string corresponding to a regular file. If the first character is “|”, open a command pipeline (can be open for read or write). FileName can also be a device name for a serial port (platform dependent). When creating a new file, optionally specify the access permissions to be given to the file in conjunction with the process’s file creation mask (default is read and write access for all).

Access specifiers:

r

Open for reading; file must already exist (default).

r+

Open for read and write; file must already exist.

w

Open for write; create new file if needed.

w+

Open for read and write; create new file if needed.

a

Open existing file for write, appending to end.

a+

Open for read and write, appending to end.

Alternate (POSIX) form for access (must specify one of the first three):

RDONLY

Open for reading.

WRONLY

Open for writing.

RDWR

Open for read and write.

You can add one or more of the following (as a list):

APPEND

Open file for append.

CREAT

Create file if it does not exist.

EXCL

Report error if file does already exist.

NOCTTY

For terminals, do not become controlling terminal for process.

NONBLOCK

Open in nonblocking mode.

TRUNC

Truncate file to zero length.

Get Tcl/Tk in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.