diff options
| author | dkf <donal.k.fellows@manchester.ac.uk> | 2021-03-31 10:38:25 (GMT) |
|---|---|---|
| committer | dkf <donal.k.fellows@manchester.ac.uk> | 2021-03-31 10:38:25 (GMT) |
| commit | 4c25696376a8c5d1f66c51a06193e8dc815287f7 (patch) | |
| tree | d9d8367476dd8deff3bebfb6f81b295845b91ee0 /doc/open.n | |
| parent | 2dab8fa488cce34d6dc5538612f1b1fba01c8ab5 (diff) | |
| parent | 9406745440cf6387d6aaa25d4b595fba069cf5d0 (diff) | |
| download | tcl-4c25696376a8c5d1f66c51a06193e8dc815287f7.zip tcl-4c25696376a8c5d1f66c51a06193e8dc815287f7.tar.gz tcl-4c25696376a8c5d1f66c51a06193e8dc815287f7.tar.bz2 | |
merge core-8-branch
Diffstat (limited to 'doc/open.n')
| -rw-r--r-- | doc/open.n | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -72,7 +72,7 @@ indicate that the opened channel should be configured as if with the reading or writing of binary data. .PP In the second form, \fIaccess\fR consists of a list of any of the -following flags, all of which have the standard POSIX meanings. +following flags, most of which have the standard POSIX meanings. One of the flags must be either \fBRDONLY\fR, \fBWRONLY\fR or \fBRDWR\fR. .TP 15 \fBRDONLY\fR @@ -453,6 +453,12 @@ application are competing for the console at the same time. If the command pipeline is started from a script, so that Tcl is not accessing the console, or if the command pipeline does not use standard input or output, but is redirected from or to a file, then the above problems do not occur. +.PP +Files opened in the +.QW \fBa\fR +mode or with the \fBAPPEND\fR flag set are implemented by seeking immediately +before each write, which is not an atomic operation and does not carry the +guarantee of strict appending that is present on POSIX platforms. .RE .TP \fBUnix\fR\0\0\0\0\0\0\0 @@ -527,6 +533,19 @@ Note that the equivalent options exist on Unix, but are on the serial channel type. .VE "8.7, TIP 160" .SH "EXAMPLES" +Open a file for writing, forcing it to be created and raising an error if it +already exists. +.PP +.CS +set myNewFile [\fBopen\fR filename.txt {WRONLY CREAT EXCL}] +.CE +.PP +Open a file for writing as a log file. +.PP +.CS +set myLogFile [\fBopen\fR filename.log "a"] +fconfigure $myLogFile -buffering line +.CE .PP Open a command pipeline and catch any errors: .PP @@ -538,6 +557,18 @@ if {[catch {close $fl} err]} { } .CE .PP +Open a command pipeline and read binary data from it. Note the unusual form +with +.QW |[list +that handles non-trivial edge cases with arguments that potentially have +spaces in. +.PP +.CS +set fl [\fBopen\fR |[list create_image_data $input] "rb"] +set binData [read $fl] +close $fl +.CE +.PP .VS "8.7, TIP 160" Read a password securely from the user (assuming that the script is being run interactively): |
