summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2021-03-30 10:14:20 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2021-03-30 10:14:20 (GMT)
commit73953be8b1584077829153afd6a58d2965e9f60c (patch)
tree9090934259648a45771fced64edaa4571eb10bbe
parent9eb5b14a3c8a078ee645a69b398cc03579126c05 (diff)
parent63f4be3aa2f1fe3a2f36da8509a5b02b8381870d (diff)
downloadtcl-73953be8b1584077829153afd6a58d2965e9f60c.zip
tcl-73953be8b1584077829153afd6a58d2965e9f60c.tar.gz
tcl-73953be8b1584077829153afd6a58d2965e9f60c.tar.bz2
Improve documentation for exec and open, especially in relation to binary pipelines
-rw-r--r--doc/exec.n6
-rw-r--r--doc/open.n36
2 files changed, 40 insertions, 2 deletions
diff --git a/doc/exec.n b/doc/exec.n
index 04b5269..d7fd96b 100644
--- a/doc/exec.n
+++ b/doc/exec.n
@@ -22,6 +22,10 @@ of one or more subprocesses to execute.
The arguments take the form of a standard shell pipeline
where each \fIarg\fR becomes one word of a command, and
each distinct command becomes a subprocess.
+The result of the command is the standard output of the final subprocess in
+the pipeline, interpreted using the system \fBencoding\fR; to use any other
+encoding (especially including binary data), the pipeline must be
+\fBopen\fRed, configured and read explicitly.
.PP
If the initial arguments to \fBexec\fR start with \fB\-\fR then
they are treated as command-line switches and are not part
@@ -413,7 +417,9 @@ With the file \fIcmp.bat\fR looking something like:
.CS
@gcc %*
.CE
+.PP
or like another variant using single parameters:
+.PP
.CS
@gcc %1 %2 %3 %4 %5 %6 %7 %8 %9
.CE
diff --git a/doc/open.n b/doc/open.n
index 1cccc0a..782183c 100644
--- a/doc/open.n
+++ b/doc/open.n
@@ -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
@@ -383,6 +383,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
@@ -408,7 +414,21 @@ 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
.PP
Open a command pipeline and catch any errors:
.PP
@@ -419,6 +439,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)