Imported upstream version 1.5
[manpages-zh.git] / raw / mann / open.n
blob193d3d7ac4e79cc90f83b29815a4c9b10abde996
1 '\"
2 '\" Copyright (c) 1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4 '\"
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 '\"
8 '\" RCS: @(#) $Id: open.n,v 1.1 2003/12/20 03:31:54 bbbush Exp $
9 '\"
10 '\" The definitions below are for supplemental macros used in Tcl/Tk
11 '\" manual entries.
12 '\"
13 '\" .AP type name in/out ?indent?
14 '\" Start paragraph describing an argument to a library procedure.
15 '\" type is type of argument (int, etc.), in/out is either "in", "out",
16 '\" or "in/out" to describe whether procedure reads or modifies arg,
17 '\" and indent is equivalent to second arg of .IP (shouldn't ever be
18 '\" needed; use .AS below instead)
19 '\"
20 '\" .AS ?type? ?name?
21 '\" Give maximum sizes of arguments for setting tab stops. Type and
22 '\" name are examples of largest possible arguments that will be passed
23 '\" to .AP later. If args are omitted, default tab stops are used.
24 '\"
25 '\" .BS
26 '\" Start box enclosure. From here until next .BE, everything will be
27 '\" enclosed in one large box.
28 '\"
29 '\" .BE
30 '\" End of box enclosure.
31 '\"
32 '\" .CS
33 '\" Begin code excerpt.
34 '\"
35 '\" .CE
36 '\" End code excerpt.
37 '\"
38 '\" .VS ?version? ?br?
39 '\" Begin vertical sidebar, for use in marking newly-changed parts
40 '\" of man pages. The first argument is ignored and used for recording
41 '\" the version when the .VS was added, so that the sidebars can be
42 '\" found and removed when they reach a certain age. If another argument
43 '\" is present, then a line break is forced before starting the sidebar.
44 '\"
45 '\" .VE
46 '\" End of vertical sidebar.
47 '\"
48 '\" .DS
49 '\" Begin an indented unfilled display.
50 '\"
51 '\" .DE
52 '\" End of indented unfilled display.
53 '\"
54 '\" .SO
55 '\" Start of list of standard options for a Tk widget. The
56 '\" options follow on successive lines, in four columns separated
57 '\" by tabs.
58 '\"
59 '\" .SE
60 '\" End of list of standard options for a Tk widget.
61 '\"
62 '\" .OP cmdName dbName dbClass
63 '\" Start of description of a specific option. cmdName gives the
64 '\" option's name as specified in the class command, dbName gives
65 '\" the option's name in the option database, and dbClass gives
66 '\" the option's class in the option database.
67 '\"
68 '\" .UL arg1 arg2
69 '\" Print arg1 underlined, then print arg2 normally.
70 '\"
71 '\" RCS: @(#) $Id: open.n,v 1.1 2003/12/20 03:31:54 bbbush Exp $
72 '\"
73 '\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
74 .if t .wh -1.3i ^B
75 .nr ^l \n(.l
76 .ad b
77 '\" # Start an argument description
78 .de AP
79 .ie !"\\$4"" .TP \\$4
80 .el \{\
81 . ie !"\\$2"" .TP \\n()Cu
82 . el .TP 15
83 .\}
84 .ta \\n()Au \\n()Bu
85 .ie !"\\$3"" \{\
86 \&\\$1 \\fI\\$2\\fP (\\$3)
87 .\".b
88 .\}
89 .el \{\
90 .br
91 .ie !"\\$2"" \{\
92 \&\\$1 \\fI\\$2\\fP
93 .\}
94 .el \{\
95 \&\\fI\\$1\\fP
96 .\}
97 .\}
99 '\" # define tabbing values for .AP
100 .de AS
101 .nr )A 10n
102 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
103 .nr )B \\n()Au+15n
105 .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
106 .nr )C \\n()Bu+\\w'(in/out)'u+2n
108 .AS Tcl_Interp Tcl_CreateInterp in/out
109 '\" # BS - start boxed text
110 '\" # ^y = starting y location
111 '\" # ^b = 1
112 .de BS
114 .mk ^y
115 .nr ^b 1u
116 .if n .nf
117 .if n .ti 0
118 .if n \l'\\n(.lu\(ul'
119 .if n .fi
121 '\" # BE - end boxed text (draw box now)
122 .de BE
124 .ti 0
125 .mk ^t
126 .ie n \l'\\n(^lu\(ul'
127 .el \{\
128 .\" Draw four-sided box normally, but don't draw top of
129 .\" box if the box started on an earlier page.
130 .ie !\\n(^b-1 \{\
131 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
133 .el \}\
134 \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
139 .nr ^b 0
141 '\" # VS - start vertical sidebar
142 '\" # ^Y = starting y location
143 '\" # ^v = 1 (for troff; for nroff this doesn't matter)
144 .de VS
145 .if !"\\$2"" .br
146 .mk ^Y
147 .ie n 'mc \s12\(br\s0
148 .el .nr ^v 1u
150 '\" # VE - end of vertical sidebar
151 .de VE
152 .ie n 'mc
153 .el \{\
154 .ev 2
156 .ti 0
157 .mk ^t
158 \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
159 .sp -1
163 .nr ^v 0
165 '\" # Special macro to handle page bottom: finish off current
166 '\" # box/sidebar if in box/sidebar mode, then invoked standard
167 '\" # page bottom macro.
168 .de ^B
169 .ev 2
170 'ti 0
172 .mk ^t
173 .if \\n(^b \{\
174 .\" Draw three-sided box if this is the box's first page,
175 .\" draw two sides but no top otherwise.
176 .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
177 .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
179 .if \\n(^v \{\
180 .nr ^x \\n(^tu+1v-\\n(^Yu
181 \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
186 .if \\n(^b \{\
187 .mk ^y
188 .nr ^b 2
190 .if \\n(^v \{\
191 .mk ^Y
194 '\" # DS - begin display
195 .de DS
200 '\" # DE - end display
201 .de DE
206 '\" # SO - start of list of standard options
207 .de SO
208 .SH "STANDARD OPTIONS"
211 .ta 5.5c 11c
212 .ft B
214 '\" # SE - end of list of standard options
215 .de SE
217 .ft R
219 See the \\fBoptions\\fR manual entry for details on the standard options.
221 '\" # OP - start of full description for a single option
222 .de OP
225 .ta 4c
226 Command-Line Name: \\fB\\$1\\fR
227 Database Name: \\fB\\$2\\fR
228 Database Class: \\fB\\$3\\fR
232 '\" # CS - begin code excerpt
233 .de CS
236 .ta .25i .5i .75i 1i
238 '\" # CE - end code excerpt
239 .de CE
243 .de UL
244 \\$1\l'|0\(ul'\\$2
246 .TH open n 7.6 Tcl "Tcl Built-In Commands"
248 '\" Note: do not modify the .SH NAME line immediately below!
249 .SH NAME
250 open \- Open a file-based or command pipeline channel
251 .SH SYNOPSIS
253 \fBopen \fIfileName\fR
255 \fBopen \fIfileName access\fR
257 \fBopen \fIfileName access permissions\fR
260 .SH DESCRIPTION
263 This command opens a file, serial port, or command pipeline and returns a
265 channel identifier that may be used in future invocations of commands like
266 \fBread\fR, \fBputs\fR, and \fBclose\fR.
267 If the first character of \fIfileName\fR is not \fB|\fR then
268 the command opens a file:
269 \fIfileName\fR gives the name of the file to open, and it must conform to the
270 conventions described in the \fBfilename\fR manual entry.
272 The \fIaccess\fR argument, if present, indicates the way in which the file
273 (or command pipeline) is to be accessed.
274 In the first form \fIaccess\fR may have any of the following values:
275 .TP 15
276 \fBr\fR
277 Open the file for reading only; the file must already exist. This is the
278 default value if \fIaccess\fR is not specified.
279 .TP 15
280 \fBr+\fR
281 Open the file for both reading and writing; the file must
282 already exist.
283 .TP 15
284 \fBw\fR
285 Open the file for writing only. Truncate it if it exists. If it doesn't
286 exist, create a new file.
287 .TP 15
288 \fBw+\fR
289 Open the file for reading and writing. Truncate it if it exists.
290 If it doesn't exist, create a new file.
291 .TP 15
292 \fBa\fR
293 Open the file for writing only. If the file doesn't exist,
294 create a new empty file.
295 Set the initial access position to the end of the file.
296 .TP 15
297 \fBa+\fR
298 Open the file for reading and writing. If the file doesn't exist,
299 create a new empty file.
300 Set the initial access position to the end of the file.
302 In the second form, \fIaccess\fR consists of a list of any of the
303 following flags, all of which have the standard POSIX meanings.
304 One of the flags must be either \fBRDONLY\fR, \fBWRONLY\fR or \fBRDWR\fR.
305 .TP 15
306 \fBRDONLY\fR
307 Open the file for reading only.
308 .TP 15
309 \fBWRONLY\fR
310 Open the file for writing only.
311 .TP 15
312 \fBRDWR\fR
313 Open the file for both reading and writing.
314 .TP 15
315 \fBAPPEND\fR
316 Set the file pointer to the end of the file prior to each write.
317 .TP 15
318 \fBCREAT\fR
319 Create the file if it doesn't already exist (without this flag it
320 is an error for the file not to exist).
321 .TP 15
322 \fBEXCL\fR
323 If \fBCREAT\fR is also specified, an error is returned if the
324 file already exists.
325 .TP 15
326 \fBNOCTTY\fR
327 If the file is a terminal device, this flag prevents the file from
328 becoming the controlling terminal of the process.
329 .TP 15
330 \fBNONBLOCK\fR
331 Prevents the process from blocking while opening the file, and
332 possibly in subsequent I/O operations. The exact behavior of
333 this flag is system- and device-dependent; its use is discouraged
334 (it is better to use the \fBfconfigure\fR command to put a file
335 in nonblocking mode).
336 For details refer to your system documentation on the \fBopen\fR system
337 call's \fBO_NONBLOCK\fR flag.
338 .TP 15
339 \fBTRUNC\fR
340 If the file exists it is truncated to zero length.
342 If a new file is created as part of opening it, \fIpermissions\fR
343 (an integer) is used to set the permissions for the new file in
344 conjunction with the process's file mode creation mask.
345 \fIPermissions\fR defaults to 0666.
347 '\" Not versioned as advice applies to all recent versions of Tcl.
348 '\" Prior to that, Tcl didn't really support binary files anyway...
350 Note that if you are going to be reading or writing binary data from
351 the channel created by this command, you should use the
352 \fBfconfigure\fR command to change the \fB-translation\fR option of
353 the channel to \fBbinary\fR before transferring any binary data. This
354 is in contrast to the ``b'' character passed as part of the equivalent
355 of the \fIaccess\fR parameter to some versions of the C library
356 \fIfopen()\fR function.
358 .SH "COMMAND PIPELINES"
360 If the first character of \fIfileName\fR is ``|'' then the
361 remaining characters of \fIfileName\fR are treated as a list of arguments
362 that describe a command pipeline to invoke, in the same style as the
363 arguments for \fBexec\fR.
364 In this case, the channel identifier returned by \fBopen\fR may be used
365 to write to the command's input pipe or read from its output pipe,
366 depending on the value of \fIaccess\fR.
367 If write-only access is used (e.g. \fIaccess\fR is \fBw\fR), then
368 standard output for the pipeline is directed to the current standard
369 output unless overridden by the command.
370 If read-only access is used (e.g. \fIaccess\fR is \fBr\fR),
371 standard input for the pipeline is taken from the current standard
372 input unless overridden by the command.
373 .SH "SERIAL COMMUNICATIONS"
376 If \fIfileName\fR refers to a serial port, then the specified serial port
377 is opened and initialized in a platform-dependent manner. Acceptable
378 values for the \fIfileName\fR to use to open a serial port are described in
379 the PORTABILITY ISSUES section.
381 .SH "CONFIGURATION OPTIONS"
382 The \fBfconfigure\fR command can be used to query and set the following
383 configuration option for open serial ports:
385 \fB\-mode \fIbaud\fB,\fIparity\fB,\fIdata\fB,\fIstop\fR
387 This option is a set of 4 comma-separated values: the baud rate, parity,
388 number of data bits, and number of stop bits for this serial port. The
389 \fIbaud\fR rate is a simple integer that specifies the connection speed.
390 \fIParity\fR is one of the following letters: \fBn\fR, \fBo\fR, \fBe\fR,
391 \fBm\fR, \fBs\fR; respectively signifying the parity options of ``none'',
392 ``odd'', ``even'', ``mark'', or ``space''. \fIData\fR is the number of
393 data bits and should be an integer from 5 to 8, while \fIstop\fR is the
394 number of stop bits and should be the integer 1 or 2.
396 \fB\-pollinterval \fImsec\fR
398 This option, available only on Windows for serial ports, is used to
399 set the maximum time between polling for fileevents. This affects the
400 time interval between checking for events throughout the Tcl
401 interpreter (the smallest value always wins). Use this option only if
402 you want to poll the serial port more often than 10 msec (the default).
404 \fB\-lasterror\fR
406 This option is available only on Windows for serial ports, and is
407 query only (will only be reported when directly requested).
408 In case of a serial communication error, \fBread\fR or \fBputs\fR
409 returns a general Tcl file I/O error.
410 \fBfconfigure -lasterror\fR can be called to get a list
411 of error details (e.g. FRAME RXOVER).
415 .SH "PORTABILITY ISSUES"
418 \fBWindows \fR(all versions)
420 Valid values for \fIfileName\fR to open a serial port are of the form
421 \fBcom\fIX\fB:\fR, where \fIX\fR is a number, generally from 1 to 4.
422 This notation only works for serial ports from 1 to 9, if the system
423 happens to have more than four. An attempt to open a serial port that
424 does not exist or has a number greater than 9 will fail. An alternate
425 form of opening serial ports is to use the filename \fB\e\e.\ecomX\fR,
426 where X is any number that corresponds to a serial port; please note
427 that this method is considerably slower on Windows 95 and Windows 98.
429 \fBWindows NT\fR
431 When running Tcl interactively, there may be some strange interactions
432 between the real console, if one is present, and a command pipeline that uses
433 standard input or output. If a command pipeline is opened for reading, some
434 of the lines entered at the console will be sent to the command pipeline and
435 some will be sent to the Tcl evaluator. If a command pipeline is opened for
436 writing, keystrokes entered into the console are not visible until the the
437 pipe is closed. This behavior occurs whether the command pipeline is
438 executing 16-bit or 32-bit applications. These problems only occur because
439 both Tcl and the child application are competing for the console at
440 the same time. If the command pipeline is started from a script, so that Tcl
441 is not accessing the console, or if the command pipeline does not use
442 standard input or output, but is redirected from or to a file, then the
443 above problems do not occur.
445 \fBWindows 95\fR
447 A command pipeline that executes a 16-bit DOS application cannot be opened
448 for both reading and writing, since 16-bit DOS applications that receive
449 standard input from a pipe and send standard output to a pipe run
450 synchronously. Command pipelines that do not execute 16-bit DOS
451 applications run asynchronously and can be opened for both reading and
452 writing.
454 When running Tcl interactively, there may be some strange interactions
455 between the real console, if one is present, and a command pipeline that uses
456 standard input or output. If a command pipeline is opened for reading from
457 a 32-bit application, some of the keystrokes entered at the console will be
458 sent to the command pipeline and some will be sent to the Tcl evaluator. If
459 a command pipeline is opened for writing to a 32-bit application, no output
460 is visible on the console until the the pipe is closed. These problems only
461 occur because both Tcl and the child application are competing for the
462 console at the same time. If the command pipeline is started from a script,
463 so that Tcl is not accessing the console, or if the command pipeline does
464 not use standard input or output, but is redirected from or to a file, then
465 the above problems do not occur.
467 Whether or not Tcl is running interactively, if a command pipeline is opened
468 for reading from a 16-bit DOS application, the call to \fBopen\fR will not
469 return until end-of-file has been received from the command pipeline's
470 standard output. If a command pipeline is opened for writing to a 16-bit DOS
471 application, no data will be sent to the command pipeline's standard output
472 until the pipe is actually closed. This problem occurs because 16-bit DOS
473 applications are run synchronously, as described above.
475 \fBMacintosh\fR
477 Opening a serial port is not currently implemented under Macintosh.
479 Opening a command pipeline is not supported under Macintosh, since
480 applications do not support the concept of standard input or output.
482 \fBUnix\fR\0\0\0\0\0\0\0
484 Valid values for \fIfileName\fR to open a serial port are generally of the
485 form \fB/dev/tty\fIX\fR, where \fIX\fR is \fBa\fR or \fBb\fR, but the name
486 of any pseudo-file that maps to a serial port may be used.
488 When running Tcl interactively, there may be some strange interactions
489 between the console, if one is present, and a command pipeline that uses
490 standard input. If a command pipeline is opened for reading, some
491 of the lines entered at the console will be sent to the command pipeline and
492 some will be sent to the Tcl evaluator. This problem only occurs because
493 both Tcl and the child application are competing for the console at the
494 same time. If the command pipeline is started from a script, so that Tcl is
495 not accessing the console, or if the command pipeline does not use standard
496 input, but is redirected from a file, then the above problem does not occur.
498 See the PORTABILITY ISSUES section of the \fBexec\fR command for additional
499 information not specific to command pipelines about executing
500 applications on the various platforms
502 .SH "SEE ALSO"
503 file(n), close(n), filename(n), fconfigure(n), gets(n), read(n),
504 puts(n), exec(n), fopen(1)
506 .SH KEYWORDS
507 access mode, append, create, file, non-blocking, open, permissions,
508 pipeline, process, serial