📄 open.n
字号:
'\"'\" Copyright (c) 1993 The Regents of the University of California.'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" SCCS: @(#) open.n 1.16 97/01/14 18:00:35'\" .so man.macros.TH open n 7.6 Tcl "Tcl Built-In Commands".BS'\" Note: do not modify the .SH NAME line immediately below!.SH NAMEopen \- Open a file-based or command pipeline channel.SH SYNOPSIS.sp\fBopen \fIfileName\fR.br\fBopen \fIfileName access\fR.br\fBopen \fIfileName access permissions\fR.BE.SH DESCRIPTION.PP.VSThis command opens a file, serial port, or command pipeline and returns a.VEchannel identifier that may be used in future invocations of commands like\fBread\fR, \fBputs\fR, and \fBclose\fR.If the first character of \fIfileName\fR is not \fB|\fR thenthe command opens a file:\fIfileName\fR gives the name of the file to open, and it must conform to theconventions described in the \fBfilename\fR manual entry..PPThe \fIaccess\fR argument, if present, indicates the way in which the file(or command pipeline) is to be accessed.In the first form \fIaccess\fR may have any of the following values:.TP 15\fBr\fROpen the file for reading only; the file must already exist. This is thedefault value if \fIaccess\fR is not specified..TP 15\fBr+\fROpen the file for both reading and writing; the file mustalready exist..TP 15\fBw\fROpen the file for writing only. Truncate it if it exists. If it doesn'texist, create a new file..TP 15\fBw+\fROpen the file for reading and writing. Truncate it if it exists.If it doesn't exist, create a new file..TP 15\fBa\fROpen the file for writing only. The file must already exist, and the fileis positioned so that new data is appended to the file..TP 15\fBa+\fROpen the file for reading and writing. If the file doesn't exist,create a new empty file.Set the initial access position to the end of the file..PPIn the second form, \fIaccess\fR consists of a list of any of thefollowing flags, all of which have the standard POSIX meanings.One of the flags must be either \fBRDONLY\fR, \fBWRONLY\fR or \fBRDWR\fR..TP 15\fBRDONLY\fROpen the file for reading only..TP 15\fBWRONLY\fROpen the file for writing only..TP 15\fBRDWR\fROpen the file for both reading and writing..TP 15\fBAPPEND\fRSet the file pointer to the end of the file prior to each write..TP 15\fBCREAT\fRCreate the file if it doesn't already exist (without this flag itis an error for the file not to exist)..TP 15\fBEXCL\fRIf \fBCREAT\fR is also specified, an error is returned if thefile already exists..TP 15\fBNOCTTY\fRIf the file is a terminal device, this flag prevents the file frombecoming the controlling terminal of the process..TP 15\fBNONBLOCK\fRPrevents the process from blocking while opening the file, andpossibly in subsequent I/O operations. The exact behavior ofthis flag is system- and device-dependent; its use is discouraged(it is better to use the \fBfconfigure\fR command to put a filein nonblocking mode).For details refer to your system documentation on the \fBopen\fR systemcall's \fBO_NONBLOCK\fR flag..TP 15\fBTRUNC\fRIf the file exists it is truncated to zero length..PPIf a new file is created as part of opening it, \fIpermissions\fR(an integer) is used to set the permissions for the new file inconjunction with the process's file mode creation mask.\fIPermissions\fR defaults to 0666..SH "COMMAND PIPELINES".PPIf the first character of \fIfileName\fR is ``|'' then theremaining characters of \fIfileName\fR are treated as a list of argumentsthat describe a command pipeline to invoke, in the same style as thearguments for \fBexec\fR.In this case, the channel identifier returned by \fBopen\fR may be usedto write to the command's input pipe or read from its output pipe,depending on the value of \fIaccess\fR.If write-only access is used (e.g. \fIaccess\fR is \fBw\fR), thenstandard output for the pipeline is directed to the current standardoutput unless overridden by the command.If read-only access is used (e.g. \fIaccess\fR is \fBr\fR),standard input for the pipeline is taken from the current standardinput unless overridden by the command..SH "SERIAL COMMUNICATIONS".VS.PPIf \fIfileName\fR refers to a serial port, then the specified serial portis opened and initialized in a platform-dependent manner. Acceptablevalues for the \fIfileName\fR to use to open a serial port are described inthe PORTABILITY ISSUES section..SH "CONFIGURATION OPTIONS"The \fBfconfigure\fR command can be used to query and set the followingconfiguration option for open serial ports:.TP\fB\-mode \fIbaud\fB,\fIparity\fB,\fIdata\fB,\fIstop\fR.This option is a set of 4 comma-separated values: the baud rate, parity,number of data bits, and number of stop bits for this serial port. The\fIbaud\fR rate is a simple integer that specifies the connection speed.\fIParity\fR is one of the following letters: \fBn\fR, \fBo\fR, \fBe\fR,\fBm\fR, \fBs\fR; respectively signifying the parity options of ``none'',``odd'', ``even'', ``mark'', or ``space''. \fIData\fR is the number ofdata bits and should be an integer from 5 to 8, while \fIstop\fR is thenumber of stop bits and should be the integer 1 or 2..VE.VS.SH "PORTABILITY ISSUES".sp.TP\fBWindows \fR(all versions).Valid values for \fIfileName\fR to open a serial port are of the form\fBcom\fIX\fB:\fR, where \fIX\fR is a number, generally from 1 to 4. Anattempt to open a serial port that does not exist will fail..TP\fBWindows NT\fR.When running Tcl interactively, there may be some strange interactionsbetween the real console, if one is present, and a command pipeline that usesstandard input or output. If a command pipeline is opened for reading, someof the lines entered at the console will be sent to the command pipeline andsome will be sent to the Tcl evaluator. If a command pipeline is opened forwriting, keystrokes entered into the console are not visible until the thepipe is closed. This behavior occurs whether the command pipeline isexecuting 16-bit or 32-bit applications. These problems only occur becauseboth Tcl and the child application are competing for the console atthe same time. If the command pipeline is started from a script, so that Tclis not accessing the console, or if the command pipeline does not usestandard input or output, but is redirected from or to a file, then theabove problems do not occur. .TP\fBWindows 95\fR .A command pipeline that executes a 16-bit DOS application cannot be openedfor both reading and writing, since 16-bit DOS applications that receivestandard input from a pipe and send standard output to a pipe runsynchronously. Command pipelines that do not execute 16-bit DOSapplications run asynchronously and can be opened for both reading andwriting. .spWhen running Tcl interactively, there may be some strange interactionsbetween the real console, if one is present, and a command pipeline that usesstandard input or output. If a command pipeline is opened for reading froma 32-bit application, some of the keystrokes entered at the console will besent to the command pipeline and some will be sent to the Tcl evaluator. Ifa command pipeline is opened for writing to a 32-bit application, no outputis visible on the console until the the pipe is closed. These problems onlyoccur because both Tcl and the child application are competing for theconsole 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 doesnot use standard input or output, but is redirected from or to a file, thenthe above problems do not occur. .spWhether or not Tcl is running interactively, if a command pipeline is openedfor reading from a 16-bit DOS application, the call to \fBopen\fR will notreturn until end-of-file has been received from the command pipeline'sstandard output. If a command pipeline is opened for writing to a 16-bit DOSapplication, no data will be sent to the command pipeline's standard outputuntil the pipe is actually closed. This problem occurs because 16-bit DOSapplications are run synchronously, as described above. .TP\fBWindows 3.X\fR .A command pipeline can execute 16-bit or 32-bit DOS or Windowsapplications, but the call to \fBopen\fR will not return until the lastprogram in the pipeline has finished executing; command pipelines runsynchronously. If the pipeline is opened with write access (either justwriting or both reading and writing) the first application in thepipeline will instead see an immediate end-of-file; any data the callerwrites to the open pipe will instead be discarded..spSince Tcl cannot be run with a real console under Windows 3.X, there areno interactions between command pipelines and the console..TP\fBMacintosh\fR.Opening a serial port is not currently implemented under Macintosh..spOpening a command pipeline is not supported under Macintosh, since applications do not support the concept of standard input or output..TP\fBUnix\fR\0\0\0\0\0\0\0.Valid values for \fIfileName\fR to open a serial port are generally of theform \fB/dev/tty\fIX\fR, where \fIX\fR is \fBa\fR or \fBb\fR, but the nameof any pseudo-file that maps to a serial port may be used..spWhen running Tcl interactively, there may be some strange interactionsbetween the console, if one is present, and a command pipeline that usesstandard input. If a command pipeline is opened for reading, someof the lines entered at the console will be sent to the command pipeline andsome will be sent to the Tcl evaluator. This problem only occurs becauseboth Tcl and the child application are competing for the console at thesame time. If the command pipeline is started from a script, so that Tcl isnot accessing the console, or if the command pipeline does not use standardinput, but is redirected from a file, then the above problem does not occur. .LPSee the PORTABILITY ISSUES section of the \fBexec\fR command for additionalinformation not specific to command pipelines about executingapplications on the various platforms.SH "SEE ALSO"close(n), filename(n), gets(n), read(n), puts(n), exec(n).VE.SH KEYWORDSaccess mode, append, create, file, non-blocking, open, permissions,pipeline, process, serial
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -