Imported upstream version 1.5
[manpages-zh.git] / src / mann / open.n
blob7c83eecf1fe56a1f20802d9173c1b4e2cb7984aa
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.2 2003/11/24 05:09:59 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.2 2003/11/24 05:09:59 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 \- 打开基于文件或命令管道的一个通道
251 .SH "总览 SYNOPSIS"
253 \fBopen \fIfileName\fR
255 \fBopen \fIfileName access\fR
257 \fBopen \fIfileName access permissions\fR
260 .SH "描述 DESCRIPTION"
263 这个命令打开一个文件、串行端口、或命令管道并返回一个
265 通道标识符用于将来被命令如 \fBread\fR、\fBputs\fR、和\fBclose \fR调用。如果 \fIfileName\fR 的第一个字符不是“|”则命令打开一个文件: \fIfileName\fR 给出要打开的文件的名字,并且它必须符合在 \fBfilename\fR 手册条目中描述的规范。
267 如果存在 \fIaccess\fR 参数,则它指示以何种方式访问文件(或命令管道)。在第一种形式下 \fIaccess\fR 可以是下列值:
268 .TP 15
269 \fBr\fR
270 为只读而打开文件;文件必须已经存在。如果未指定 \fIaccess\fR 则这个值是缺省值。
271 .TP 15
272 \fBr+\fR
273 为读写而打开文件;文件必须已经存在。
274 .TP 15
275 \fBw\fR
276 为只写而打开文件。如果文件已经存在则截断(truncate)它,如果文件不存在则建立一个新文件。
277 .TP 15
278 \fBw+\fR
279 为读写而打开文件。如果文件已经存在则截断(truncate)它,如果文件不存在则建立一个新文件。
280 .TP 15
281 \fBa\fR
282 为只读而打开文件。如果文件不存在,则建立一个新的空文件。设置初始访问位置为文件的结束处。
283 .TP 15
284 \fBa+\fR
285 为读写而打开文件。如果文件不存在,则建立一个新的空文件。设置初始访问位置为文件的结束处。
287 在第二种形式下,\fIaccess\fR 由某些下列标志的一个列表构成,所有这些都有标准的 POSIX 意义。 必须有一个标志是 \fBRDONLY\fR、\fBWRONLY\fR 或 \fBRDWR\fR 中的一个。
288 .TP 15
289 \fBRDONLY\fR
290 为只读而打开文件。
291 .TP 15
292 \fBWRONLY\fR
293 为只写而打开文件。
294 .TP 15
295 \fBRDWR\fR
296 为读写而打开文件。
297 .TP 15
298 \fBAPPEND\fR
299 在每次写之前把指针设置到文件的结束处。
300 .TP 15
301 \fBCREAT\fR
302 如果文件不存在则建立这个文件(如果没有这个标志,在文件不存在时返回一个错误)。
303 .TP 15
304 \fBEXCL\fR
305 如果还指定了 \fBCREAT\fR,如果文件已经存在则返回一个错误。
306 .TP 15
307 \fBNOCTTY\fR
308 如果文件是一个终端设备,这个标志防止这个文件成为这个进程的控制终端。
309 .TP 15
310 \fBNONBLOCK\fR
311 在打开文件和可能的后续 I/O
312 操作期间防止过程阻塞。这个标志的真实行为是依赖于系统的和依赖于设备的;不鼓励使用它(更好是使用 \fBfconfigure\fR 命令来使一个文件进入非阻塞模式)。详情参见你的系统文档中的 \fBopen\fR 系统调用的 \fBO_NONBLOCK\fR 标志。
313 .TP 15
314 \fBTRUNC\fR
315 如果文件存在则截断其为零长度。
317 如果作为打开过程的一部分而建立了一个新文件,使用 \fIpermissions\fR (一个整数)并联合进程的文件模式建立掩码为新文件设置权限。\fIPermissions\fR 缺省为 0666。
319 '\" Not versioned as advice applies to all recent versions of Tcl.
320 '\" Prior to that, Tcl didn't really support binary files anyway...
322 Note that if you are going to be reading or writing binary data from
323 the channel created by this command, you should use the
324 \fBfconfigure\fR command to change the \fB-translation\fR option of
325 the channel to \fBbinary\fR before transferring any binary data. This
326 is in contrast to the ``b'' character passed as part of the equivalent
327 of the \fIaccess\fR parameter to some versions of the C library
328 \fIfopen()\fR function.
330 .SH "命令管道 COMMAND PIPELINES"
332 如果 \fIfileName\fR is 的第一个字符是“|”,则把 \fIfileName\fR 的余下的字符被作为描述要调用的一个命令管道的参数的一个列表来对待,与 \fBexec \fR对待参数的方式相同。在这种情况下,依赖于 access 的值,使用由 \fBopen\fR 返回的通道标识符来向这个命令的输入管道写或从它的输出管道读。如果使用了只写访问(例如, \fIaccess\fR 是 \fBw\fR),则除非被这个命令所屏弃(override),这个(命令)管道的标准输出被定向到当前的标准输出上。如果使用了只读访问(例如,\fIaccess\fR 是 \fBr\fR),则除非被这个命令所屏弃(override),这个(命令)管道的标准输入接受当前的标准输入。
334 译注
336 打开用来写的命令管道
338 Tcl ==> Pipeline ==> command
340 +--------+ +--------+ +--------+ +--------+
341 | stdin |<------+ stdin | +-->| pipein | +--+ stdin |
342 +--------+ +--------+ | +--------+ | +--------+
343 | stdout |<--+---+ stdout | | | pipeout|<--+ | stdout +--+
344 +--------+ | +--------+ | +--------+ +--------+ |
345 | | stderr | | | stderr | |
346 | +--------+ | +--------+ |
347 | | channel+--+ |
348 | +--------+ |
349 +-----------------------------------------------+
352 打开一个用来读的命令管道
354 +-----------------------------------------------+
356 +--------+ | +--------+ +--------+ +--------+ |
357 | stdin |<--+---+ stdin | | pipein |<--+ | stdin +--+
358 +--------+ +--------+ +--------+ | +--------+
359 | stdout |<------+ stdout | +-->| pipeout| +--+ stdout |
360 +--------+ +--------+ | +--------+ +--------+
361 | stderr | | | stderr |
362 +--------+ | +--------+
363 | channel+--+
364 +--------+
365 Tcl <== Pipeline <== command
368 .SH "串行通信 SERIAL COMMUNICATIONS"
371 如果 \fIfileName\fR 参照一个串行端口,则打开特定的串行端口并以依赖于平台的方式初始化。给 \fIfileName\fR 用以打开一个串行端口的可接受的值在移植要点中描述。
373 .SH "配置选项 CONFIGURATION OPTIONS"
374 使用 \fBfconfigure\fR 命令来为打开的串行端口查询和设置下列选项:
376 \fB\-mode \fIbaud\fB,\fIparity\fB,\fIdata\fB,\fIstop\fR
378 这个选项是由逗号分隔的四个值的一个集合: 这个串行端口的波特(baud)率、奇偶校验(parity)、数据位数、和停止位。\fIbaud\fR 率是指定连接速度的一个简单整数。\fIParity\fR 是下列字母之一: \fBn\fR、\fBo\fR、\fBe\fR、\fBm\fR、\fBs\fR;分别表示奇偶校验选项“none”、“odd”、“even”、“mark”、或“space”。\fIData\fR 是数据位数,应当是从 5 到 8 中的一个整数,而 \fIstop\fR 是停止位的数目,应当是整数 1 或 2。
380 \fB\-pollinterval \fImsec\fR
382 只在 Windows 上串行端口能获得这个选项,它被用来设置文件事件轮询(poll)之间的最大时间。这影响整个 Tcl 解释器检查事件中间的时间间隔(总是采用最小的值)。只有在你想要使轮询这个串行端口的时间间隔小于 10 msec (缺省值)时才使用这个选项。
384 \fB\-lasterror\fR
386 只在 Windows 上串行端口能获得这个选项,并只能查询(只在直接请求时报告)。在串行通信出错的情况下,\fBread\fR 或 \fBputs\fR 返回一个一般 Tcl 文件 I/O 错误。可以调用 \fBfconfigure -lasterror\fR 来得到错误详情的一个列表(例如,FRAME RXOVER)。
390 .SH "移植要点 PORTABILITY ISSUES"
393 \fBWindows \fR(所有版本)
395 \fIfileName\fR 来打开一个串行端口的有效值的形式是 \fBcom\fIX\fB:\fR,这里 \fIX\fR 是一个数,一般是从 1 到 4。如果系统有多于四个串行端口,则这个符号(notation)可以表示串行端口从 1 到 9。尝试打开一个不存在或序号大于 9 的串行端口将导致错误。打开串行端口的可替代的方法是使用文件名 \fB\e\e.\ecomX\fR,这里 X 是对应于一个串行端口的任何(整)数;请注意,这个方法在 Windows 95 和 Windows 98 上相当的慢。
397 \fBWindows NT\fR
399 在交互运行 Tcl 的时候,如果存在一个控制台,则在真实的控制台和使用标准输入或输出的一个命令管道之间可能有一些奇怪的相互作用。如果为读而打开一个命令管道,在这个控制台键入的一些行将被发送到命令管道而一些行将别发送到 Tcl 求值器。如果为写而打开一个命令管道,在管道关闭之前,在这个控制台中键入的击键(keystroke)将一直是不可见的。在执行 16-bit 或 32-bit 应用程序时都可能发生这种事情。这些问题只发生在 Tcl 和子应用程序同时竞争这个控制台的时候。如果命令管道是从一个脚本中启动的,所以 Tcl 不访问控制台,或者命令管道不使用标准输出或输出,而是重定向(从或)到一个文件,那么上述问题不发生。
401 \fBWindows 95\fR
403 不能同时为读写而打开一个命令管道来执行一个 16-bit DOS 应用程序,因为从一个管道接收标准输入和向一个管道发送标准输出的(两个) 16-bit DOS 应用程序同步运行。不执行 16-bit DOS 应用程序的命令管道异步运行并且可以同时为读写而打开。
405 在交互运行 Tcl 的时候,如果存在一个控制台,则在真实的控制台和使用标准输入或输出的一个命令管道之间可能有一些奇怪的相互作用。如果为从一个 32-bit 应用程序读而打开一个命令管道,在这个控制台键入的一些击键将被发送到命令管道而一些击键将别发送到 Tcl 求值器。如果为向一个 32-bit 应用程序写而打开一个命令管道,在管道关闭之前,在控制台中将一直没有输出是可见的。这些问题只发生在 Tcl 和子应用程序同时竞争这个控制台的时候。如果命令管道是从一个脚本中启动的,所以 Tcl 不访问控制台,或者命令管道不使用标准输出或输出,而是重定向(从或)到一个文件,那么上述问题不发生。
407 不论 Tcl 是否在交互的运行,如果为从一个 16-bit DOS 应用程序读而打开一个命令管道,在从命令管道的标准输出收到文件结束之前,对 \fBopen\fR 的调用一直不返回。如果为向一个 16-bit DOS 应用程序写而打开一个命令管道,在管道实际上被关闭之前,没有数据被发送到命令管道的标准输出。象上面描述的那样,这个问题发生的原因是 16-bit DOS 应用程序同步运行。
409 \fBMacintosh\fR
411 在 Macintosh 下目前未实现打开串行端口。
413 在 Macintosh 不支持打开命令管道,原因是应用程序不支持标准输入或输出的概念。
415 \fBUnix\fR\0\0\0\0\0\0\0
417 \fIfileName\fR 来打开一个串行端口的有效值的形式是 \fB/dev/tty\fIX\fR,这里的 \fIX\fR 是 \fBa\fR 或 \fBb\fR,但是可以使用映射到一个串行端口的任何伪文件(pseudo-file)的名字。
419 在交互运行 Tcl 的时候,如果存在一个控制台,则在真实的控制台和使用标准输入或输出的一个命令管道之间可能有一些奇怪的相互作用。如果为读而打开一个命令管道,在这个控制台键入的一些行将被发送到命令管道而一些行将别发送到 Tcl 求值器。这些问题只发生在 Tcl 和子应用程序同时竞争这个控制台的时候。如果命令管道是从一个脚本中启动的,所以 Tcl 不访问控制台,或者命令管道不使用标准输出或输出,而是重定向(从或)到一个文件,那么上述问题不发生。
421 关于在不同平台上执行应用程序请参见 \fBexec\fR 命令的\fB移植要点\fR章节来得到不特定于命令管道的额外的信息。
423 .SH "参见 SEE ALSO"
424 file(n), close(n), filename(n), fconfigure(n), gets(n), read(n),
425 puts(n), exec(n), fopen(1)
427 .SH "关键字 KEYWORDS"
428 access mode, append, create, file, non-blocking, open, permissions,
429 pipeline, process, serial
431 .SH "[中文版维护人]"
432 .B 寒蝉退士
433 .SH "[中文版最新更新]"
434 .B 2001/10/16
435 .SH "《中国 Linux 论坛 man 手册页翻译计划》:"
436 .BI http://cmpp.linuxforum.net