summaryrefslogtreecommitdiffstats
path: root/doc/open.n
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2021-03-30 09:03:19 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2021-03-30 09:03:19 (GMT)
commit63f4be3aa2f1fe3a2f36da8509a5b02b8381870d (patch)
tree8b288218cdc3e086de6b22451757278151d933d1 /doc/open.n
parentd63f456a83dd1cbb7dedd7fd1148a89f0905bcd0 (diff)
downloadtcl-63f4be3aa2f1fe3a2f36da8509a5b02b8381870d.zip
tcl-63f4be3aa2f1fe3a2f36da8509a5b02b8381870d.tar.gz
tcl-63f4be3aa2f1fe3a2f36da8509a5b02b8381870d.tar.bz2
Improve documentation for exec and open, especially in relation to binary pipelines
Diffstat (limited to 'doc/open.n')
-rw-r--r--doc/open.n39
1 files changed, 36 insertions, 3 deletions
diff --git a/doc/open.n b/doc/open.n
index a9da946..844433e 100644
--- a/doc/open.n
+++ b/doc/open.n
@@ -68,7 +68,7 @@ reading or writing of binary data.
.VE 8.5
.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
@@ -351,7 +351,13 @@ pipe is closed. These problems only occur because both Tcl and the child
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.
+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
@@ -376,8 +382,23 @@ input, but is redirected from a file, then the above problem does not occur.
See the \fBPORTABILITY ISSUES\fR section of the \fBexec\fR command for
additional information not specific to command pipelines about executing
applications on the various platforms
-.SH "EXAMPLE"
+.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
.CS
set fl [\fBopen\fR "| ls this_file_does_not_exist"]
set data [read $fl]
@@ -385,6 +406,18 @@ if {[catch {close $fl} err]} {
puts "ls command failed: $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
.SH "SEE ALSO"
file(n), close(n), filename(n), fconfigure(n), gets(n), read(n),
puts(n), exec(n), pid(n), fopen(3)