1mNAME0m
       open - Open a file-based or command pipeline channel

1mSYNOPSIS0m
       1mopen 4m22mfileName0m
       1mopen 4m22mfileName24m 4maccess0m
       1mopen 4m22mfileName24m 4maccess24m 4mpermissions0m


1mDESCRIPTION0m
       This command opens a file, serial port, or command pipeline and returns
       a channel identifier that may be used in future invocations of commands
       like  1mread22m, 1mputs22m, and 1mclose22m.  If the first character of 4mfileName24m is not
       1m| 22mthen the command opens a file: 4mfileName24m gives the name of the file to
       open,  and it must conform to the conventions described in the 1mfilename0m
       manual entry.

       The 4maccess24m argument, if present, indicates the way in  which  the  file
       (or  command pipeline) is to be accessed.  In the first form 4maccess24m may
       have any of the following values:

       1mr              22mOpen the file for reading only; the  file  must  already
                      exist. This is the default value if 4maccess24m is not speci-
                      fied.

       1mr+             22mOpen the file for both reading  and  writing;  the  file
                      must already exist.

       1mw              22mOpen  the  file  for  writing  only.   Truncate it if it
                      exists.  If it doesn't exist, create a new file.

       1mw+             22mOpen the file for reading and writing.  Truncate  it  if
                      it exists.  If it doesn't exist, create a new file.

       1ma              22mOpen  the  file  for  writing only.  If the file doesn't
                      exist, create a new empty file.  Set the initial  access
                      position  to the end of the file.

       1ma+             22mOpen  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.

       In  the  second form, 4maccess24m consists of a list of any of the following
       flags, all of which have the standard POSIX meanings.  One of the flags
       must be either 1mRDONLY22m, 1mWRONLY 22mor 1mRDWR22m.

       1mRDONLY         22mOpen the file for reading only.

       1mWRONLY         22mOpen the file for writing only.

       1mRDWR           22mOpen the file for both reading and writing.

       1mAPPEND         22mSet  the  file  pointer  to the end of the file prior to
                      each write.

       1mCREAT          22mCreate the file if it  doesn't  already  exist  (without
                      this flag it is an error for the file not to exist).

       1mEXCL           22mIf  1mCREAT 22mis also specified, an error is returned if the
                      file already exists.

       1mNOCTTY         22mIf the file is a terminal device, this flag prevents the
                      file  from  becoming  the  controlling  terminal  of the
                      process.

       1mNONBLOCK       22mPrevents the process from  blocking  while  opening  the
                      file,  and  possibly  in subsequent I/O operations.  The
                      exact behavior of this flag is system- and device-depen-
                      dent;   its  use is discouraged (it is better to use the
                      1mfconfigure 22mcommand to put a file in  nonblocking  mode).
                      For  details  refer  to your system documentation on the
                      1mopen 22msystem call's 1mO_NONBLOCK 22mflag.

       1mTRUNC          22mIf the file exists it is truncated to zero length.

       If a new file is created as part of opening it, 4mpermissions24m  (an  inte-
       ger)  is  used  to  set the permissions for the new file in conjunction
       with the process's file mode creation mask.   4mPermissions24m  defaults  to
       0666.

       Note  that  if  you are going to be reading or writing binary data from
       the channel created by this command, you should use the 1mfconfigure 22mcom-
       mand  to change the 1m-translation 22moption of the channel to 1mbinary 22mbefore
       transferring any binary data.  This is in contrast to the ``b'' charac-
       ter  passed  as  part of the equivalent of the 4maccess24m parameter to some
       versions of the C library 4mfopen()24m function.

1mCOMMAND PIPELINES0m
       If the first character of 4mfileName24m is ``|'' then the remaining  charac-
       ters  of  4mfileName24m  are  treated as a list of arguments that describe a
       command pipeline to invoke, in the same  style  as  the  arguments  for
       1mexec22m.   In  this  case,  the channel identifier returned by 1mopen 22mmay be
       used to write to the command's input pipe or read from its output pipe,
       depending  on  the value of 4maccess24m.  If write-only access is used (e.g.
       4maccess24m is 1mw22m), then standard output for the pipeline is directed to  the
       current standard output unless overridden by the command.  If read-only
       access is used (e.g. 4maccess24m is 1mr22m), standard input for the  pipeline  is
       taken from the current standard input unless overridden by the command.

1mSERIAL COMMUNICATIONS0m
       If 4mfileName24m refers to a serial port, then the specified serial port  is
       opened and initialized in a platform-dependent manner.  Acceptable val-
       ues for the 4mfileName24m to use to open a serial port are described in  the
       PORTABILITY ISSUES section.


1mCONFIGURATION OPTIONS0m
       The  1mfconfigure 22mcommand can be used to query and set the following con-
       figuration option for open serial ports:

       1m-mode 4m22mbaud24m1m,4m22mparity24m1m,4m22mdata24m1m,4m22mstop0m
              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 4mbaud24m rate is a simple integer  that  specifies
              the  connection  speed.  4mParity24m is one of the following letters:
              1mn22m, 1mo22m, 1me22m, 1mm22m, 1ms22m; respectively signifying  the  parity  options  of
              ``none'',  ``odd'',  ``even'',  ``mark'', or ``space''.  4mData24m is
              the number of data bits and should be an integer from  5  to  8,
              while  4mstop24m is the number of stop bits and should be the integer
              1 or 2.

       1m-pollinterval 4m22mmsec0m
              This option, available only on Windows for serial ports, is used
              to  set  the  maximum time between polling for fileevents.  This
              affects the time interval between checking for events throughout
              the  Tcl interpreter (the smallest value always wins).  Use this
              option only if you want to poll the serial port more often  than
              10 msec (the default).

       1m-lasterror0m
              This  option  is available only on Windows for serial ports, and
              is query only (will only be reported when  directly  requested).
              In  case of a serial communication error, 1mread 22mor 1mputs 22mreturns a
              general Tcl file I/O error.  1mfconfigure -lasterror 22mcan be called
              to get a list of error details (e.g. FRAME RXOVER).


1mPORTABILITY ISSUES0m
       1mWindows 22m(all versions)
              Valid  values for 4mfileName24m to open a serial port are of the form
              1mcom4m22mX24m1m:22m, where 4mX24m is a number, generally from 1 to 4.   This  nota-
              tion only works for serial ports from 1 to 9, if the system hap-
              pens to have more than four.  An attempt to open a  serial  port
              that  does  not  exist or has a number greater than 9 will fail.
              An alternate form of opening serial ports is to use the filename
              1m\\.\comX22m,  where  X  is  any number that corresponds to a serial
              port; please note that this method  is  considerably  slower  on
              Windows 95 and Windows 98.

       1mWindows NT0m
              When running Tcl interactively, there may be some strange inter-
              actions between the real console, if one is present, and a  com-
              mand  pipeline that uses standard input or output.  If a command
              pipeline is opened for reading, some of the lines entered at the
              console  will  be  sent to the command pipeline and some will be
              sent to the Tcl evaluator.  If a command pipeline is opened  for
              writing,  keystrokes  entered  into  the console are not visible
              until the the pipe is closed.  This behavior occurs whether  the
              command  pipeline  is  executing  16-bit or 32-bit applications.
              These problems only occur because both Tcl and the child  appli-
              cation  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.

       1mWindows 950m
              A command pipeline that executes a 16-bit DOS application cannot
              be opened for both reading and writing, since 16-bit DOS  appli-
              cations  that  receive standard input from a pipe and send stan-
              dard output to a pipe run synchronously.  Command pipelines that
              do  not  execute  16-bit DOS applications run asynchronously and
              can be opened for both reading and writing.

              When running Tcl interactively, there may be some strange inter-
              actions  between the real console, if one is present, and a com-
              mand pipeline that uses standard input or output.  If a  command
              pipeline  is  opened for reading from a 32-bit application, some
              of the keystrokes entered at the console will  be  sent  to  the
              command pipeline and some will be sent to the Tcl evaluator.  If
              a command pipeline is opened for writing to  a  32-bit  applica-
              tion,  no output is visible on the console until the the 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.

              Whether  or  not  Tcl  is  running  interactively,  if a command
              pipeline is opened for reading from a  16-bit  DOS  application,
              the  call  to  1mopen  22mwill  not return until end-of-file has been
              received from the command pipeline's standard output.  If a com-
              mand pipeline is opened for writing to a 16-bit DOS application,
              no data will be sent to the command pipeline's  standard  output
              until  the pipe is actually closed.  This problem occurs because
              16-bit DOS applications  are  run  synchronously,  as  described
              above.

       1mMacintosh0m
              Opening  a serial port is not currently implemented under Macin-
              tosh.

              Opening a command pipeline is  not  supported  under  Macintosh,
              since  applications do not support the concept of standard input
              or output.

       1mUnix0m
              Valid values for 4mfileName24m to open a serial port are generally of
              the  form  1m/dev/tty4m22mX24m,  where  4mX24m  is  1ma 22mor 1mb22m, but the name of any
              pseudo-file that maps to a serial port may be used.

              When running Tcl interactively, there may be some strange inter-
              actions  between  the  console, if one is present, and a command
              pipeline that uses standard input.  If  a  command  pipeline  is
              opened  for  reading,  some  of the lines entered at the console
              will be sent to the command pipeline and some will  be  sent  to
              the  Tcl  evaluator.   This problem only occurs 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, but is redirected from a
              file, then the above problem does not occur.

       See the PORTABILITY ISSUES section of the 1mexec 22mcommand  for  additional
       information  not specific to command pipelines about executing applica-
       tions on the various platforms


1mSEE ALSO0m
       file(n),  close(n),  filename(n),  fconfigure(n),   gets(n),   read(n),
       puts(n), exec(n), fopen(1)


1mKEYWORDS0m
       access  mode,  append,  create,  file, non-blocking, open, permissions,
