Seth Woolley's Man Viewer

Manual for open - man n open

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

open(2,3,n)(n)                      Tcl Built-In Commands                     open(2,3,n)(n)



NAME
       open(2,3,n) - Open a file-based or command pipeline channel

SYNOPSIS
       open(2,3,n) fileName
       open(2,3,n) fileName access(2,5)
       open(2,3,n) fileName access(2,5) permissions


DESCRIPTION
       This command opens a file(1,n), serial port, or command pipeline and returns
       a channel identifier that may be used in(1,8) future invocations of commands
       like  read(2,n,1 builtins), puts(3,n), and close(2,7,n).  If the first character of fileName is not
       | then the command opens a file: fileName gives the name of the file(1,n) to
       open(2,3,n),  and it must conform to the conventions described in(1,8) the filename
       manual entry.

       The access(2,5) argument, if(3,n) present, indicates the way in(1,8)  which  the  file(1,n)
       (or  command pipeline) is to be accessed.  In the first form access(2,5) may
       have any of the following values:

       r              Open the file(1,n) for reading only; the  file(1,n)  must  already
                      exist. This is the default value if(3,n) access(2,5) is not speci-
                      fied.

       r+             Open the file(1,n) for both reading  and  writing;  the  file(1,n)
                      must already exist.

       w              Open  the  file(1,n)  for  writing  only.   Truncate it if(3,n) it
                      exists.  If it doesn't exist, create a new file.

       w+             Open the file(1,n) for reading and writing.  Truncate  it  if(3,n)
                      it exists.  If it doesn't exist, create a new file.

       a              Open  the  file(1,n)  for  writing only.  If the file(1,n) doesn't
                      exist, create a new empty file.  Set the initial  access(2,5)
                      position  to the end of the file.

       a+             Open  the  file(1,n)  for  reading  and writing.  If the file(1,n)
                      doesn't exist, create a new empty file.  Set the initial
                      access(2,5) position  to the end of the file.

       In  the  second form, access(2,5) 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 RDONLY, WRONLY or RDWR.

       RDONLY         Open the file(1,n) for reading only.

       WRONLY         Open the file(1,n) for writing only.

       RDWR           Open the file(1,n) for both reading and writing.

       APPEND         Set  the  file(1,n)  pointer  to the end of the file(1,n) prior to
                      each write.

       CREAT          Create the file(1,n) if(3,n) it  doesn't  already  exist  (without
                      this flag it is an error(8,n) for the file(1,n) not to exist).

       EXCL           If  CREAT is also specified, an error(8,n) is returned if(3,n) the
                      file(1,n) already exists.

       NOCTTY         If the file(1,n) is a terminal device, this flag prevents the
                      file(1,n)  from  becoming  the  controlling  terminal  of the
                      process.

       NONBLOCK       Prevents the process from  blocking  while  opening  the
                      file(1,n),  and  possibly  in(1,8) 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
                      fconfigure command to put a file(1,n) in(1,8)  nonblocking  mode).
                      For  details  refer  to your system documentation on the
                      open(2,3,n) system call's O_NONBLOCK flag.

       TRUNC          If the file(1,n) exists it is truncated to zero length.

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

       Note  that  if(3,n)  you are going to be reading or writing binary data from
       the channel created by this command, you should use the fconfigure com-
       mand  to change the -translation option of the channel to binary before
       transferring any binary data.  This is in(1,8) contrast to the ``b'' charac-
       ter  passed  as  part of the equivalent of the access(2,5) parameter to some
       versions of the C library fopen() function.


COMMAND PIPELINES
       If the first character of fileName is ``|'' then the remaining  charac-
       ters  of  fileName  are  treated as a list of arguments that describe a
       command pipeline to invoke, in(1,8) the same  style  as  the  arguments  for
       exec(3,n,1 builtins).   In  this  case,  the channel identifier returned by open(2,3,n) may be
       used to write(1,2) to the command's input pipe(2,8) or read(2,n,1 builtins) from its output pipe(2,8),
       depending  on  the value of access(2,5).  If write-only access(2,5) is used (e.g.
       access(2,5) is w), then standard output for the pipeline is directed to  the
       current standard output unless overridden by the command.  If read-only
       access(2,5) is used (e.g. access(2,5) is r), standard input for the  pipeline  is
       taken from the current standard input unless overridden by the command.
       The id of the spawned process is accessible through  the  pid  command,
       using the channel id returned by open(2,3,n) as argument.


SERIAL COMMUNICATIONS
       If  fileName refers to a serial port, then the specified serial port is
       opened and initialized in(1,8) a platform-dependent manner.  Acceptable val-
       ues  for the fileName to use to open(2,3,n) a serial port are described in(1,8) the
       PORTABILITY ISSUES section.

       The fconfigure command can be used to query and set(7,n,1 builtins) additional configu-
       ration options specific to serial ports (where supported):

       -mode baud,parity,data,stop
              This option is a set(7,n,1 builtins) of 4 comma-separated values: the baud rate,
              parity, number of data bits, and number of stop  bits  for  this
              serial  port.   The baud rate is a simple integer that specifies
              the connection speed.  Parity is one of the  following  letters:
              n,  o,  e,  m,  s; respectively signifying the parity options of
              ``none'', ``odd'', ``even'', ``mark'', or  ``space''.   Data  is
              the  number  of  data bits and should be an integer from 5 to 8,
              while stop is the number of stop bits and should be the  integer
              1 or 2.

       -handshake type
              (Windows and Unix). This option is used to setup(2,8) automatic hand-
              shake control. Note that not all handshake types maybe supported
              by  your  operating  system. The type parameter is case-indepen-
              dent.

              If type is none then any  handshake  is  switched  off.   rtscts
              activates  hardware  handshake.  Hardware  handshake signals are
              described below.  For software handshake xonxoff  the  handshake
              characters can be redefined with -xchar.  An additional hardware
              handshake dtrdsr is available only under Windows.  There  is  no
              default  handshake  configuration,  the initial value depends on
              your operating system settings.  The -handshake option cannot be
              queried.

       -queue (Windows  and  Unix). The -queue option can only be queried.  It
              returns a list of two integers representing the  current  number
              of bytes in(1,8) the input and output queue(1,3) respectively.

       -timeout msec
              (Windows  and  Unix). This option is used to set(7,n,1 builtins) the timeout(1,3x,3x cbreak) for
              blocking read(2,n,1 builtins) operations.  It  specifies  the  maximum  interval
              between  the  reception  of two bytes in(1,8) milliseconds.  For Unix
              systems the  granularity  is  100  milliseconds.   The  -timeout
              option  does  not  affect write(1,2) operations or nonblocking reads.
              This option cannot be queried.

       -ttycontrol {signal(2,7) boolean signal(2,7) boolean ...}
              (Windows and Unix). This option is used to setup(2,8)  the  handshake
              output lines (see below) permanently or to send(2,n) a BREAK over the
              serial line.  The signal(2,7) names are case-independent.  {RTS 1 DTR
              0}  sets  the RTS output to high and the DTR output to low.  The
              BREAK condition (see below) is enabled and disabled with  {BREAK
              1}  and  {BREAK 0} respectively.  It's not a good idea to change
              the RTS (or DTR) signal(2,7) with active  hardware  handshake  rtscts
              (or  dtrdsr).   The  result  is  unpredictable.  The -ttycontrol
              option cannot be queried.

       -ttystatus
              (Windows and Unix). The -ttystatus option can only  be  queried.
              It  returns the current modem status and handshake input signals
              (see below).  The result is a list of signal(2,7),value pairs with  a
              fixed  order, e.g. {CTS 1 DSR 0 RING 1 DCD 0}.  The signal(2,7) names
              are returned upper case.

       -xchar {xonChar xoffChar}
              (Windows and Unix). This option is used to query or  change  the
              software  handshake  characters.  Normally  the operating system
              default should be DC1 (0x11) and  DC3  (0x13)  representing  the
              ASCII standard XON and XOFF characters.

       -pollinterval msec
              (Windows  only).  This  option  is  used to set(7,n,1 builtins) the maximum time(1,2,n)
              between polling for fileevents.  This affects the time(1,2,n)  interval
              between  checking for events throughout the Tcl interpreter (the
              smallest value always wins).  Use this option only if(3,n)  you  want
              to  poll  the  serial  port more or less(1,3) often than 10 msec (the
              default).

       -sysbuffer inSize

       -sysbuffer {inSize outSize}
              (Windows only). This option is used to change the size  of  Win-
              dows  system  buffers for a serial channel. Especially at higher
              communication rates the default input buffer size of 4096  bytes
              can  overrun  for  latent  systems. The first form specifies the
              input buffer size, in(1,8) the second  form  both  input  and  output
              buffers are defined.

       -lasterror
              (Windows  only). This option is query only.  In case of a serial
              communication error(8,n), read(2,n,1 builtins) or puts(3,n) returns a general Tcl file(1,n) I/O
              error.   fconfigure  -lasterror  can  be called to get a list of
              error(8,n) details.  See below for  an  explanation  of  the  various
              error(8,n) codes.


SERIAL PORT SIGNALS
       RS-232  is  the  most  commonly  used standard electrical interface for
       serial communications. A negative voltage  (-3V..-12V)  define  a  mark
       (on=1) bit and a positive voltage (+3..+12V) define a space (off=0) bit
       (RS-232C).  The following signals are specified for incoming and outgo-
       ing  data,  status  lines  and handshaking. Here we are using the terms
       workstation for your  computer  and  modem  for  the  external  device,
       because  some  signal(2,7)  names (DCD, RI) come from modems. Of course your
       external device may use these signal(2,7) lines for other purposes.


       TXD(output)
              Transmitted Data: Outgoing serial data.

       RXD(input)
              Received Data:Incoming serial data.

       RTS(output)
              Request To Send: This hardware handshake line informs the  modem
              that your workstation is ready to receive data. Your workstation
              may automatically reset(1,7,1 tput) this signal(2,7) to indicate that  the  input
              buffer is full.

       CTS(input)
              Clear  To  Send: The complement to RTS. Indicates that the modem
              is ready to receive data.

       DTR(output)
              Data Terminal Ready: This signal(2,7) tells the modem that the  work-
              station is ready to establish a link. DTR is often enabled auto-
              matically whenever a serial port is opened.

       DSR(input)
              Data Set Ready: The complement to  DTR.  Tells  the  workstation
              that the modem is ready to establish a link.

       DCD(input)
              Data  Carrier  Detect:  This  line  becomes  active when a modem
              detects a "Carrier" signal.

       RI(input)
              Ring Indicator: Goes active when the modem detects  an  incoming
              call.

       BREAK  A  BREAK  condition is not a hardware signal(2,7) line, but a logical
              zero on the TXD or RXD lines for a long period of time(1,2,n),  usually
              250  to  500  milliseconds.  Normally a receive or transmit data
              signal(2,7) stays at the mark (on=1) voltage until the next character
              is  transferred. A BREAK is sometimes used to reset(1,7,1 tput) the communi-
              cations line or change  the  operating  mode  of  communications
              hardware.


ERROR CODES (Windows only)
       A  lot  of  different errors may occur during serial read(2,n,1 builtins) operations or
       during event polling in(1,8) background. The external device may  have  been
       switched  off,  the data lines may be noisy, system buffers may overrun
       or your mode settings may be wrong.  That's  why  a  reliable  software
       should  always  catch serial read(2,n,1 builtins) operations.  In cases of an error(8,n) Tcl
       returns a general file(1,n) I/O error.  Then fconfigure -lasterror may  help
       to locate the problem.  The following error(8,n) codes may be returned.


       RXOVER    Windows input buffer overrun. The data comes faster than your
                 scripts reads it or your system is overloaded. Use fconfigure
                 -sysbuffer  to  avoid a temporary bottleneck and/or make your
                 script faster.

       TXFULL    Windows output buffer overrun.  Complement  to  RXOVER.  This
                 error(8,n)  should practically not happen, because Tcl cares about
                 the output buffer status.

       OVERRUN   UART buffer overrun (hardware)  with  data  lost.   The  data
                 comes  faster than the system driver receives it.  Check your
                 advanced serial port settings  to  enable  the  FIFO  (16550)
                 buffer and/or setup(2,8) a lower(1) interrupt threshold value.

       RXPARITY  A  parity error(8,n) has been detected by your UART.  Wrong parity
                 settings with fconfigure -mode or a noisy data line (RXD) may
                 cause this error.

       FRAME     A  stop-bit error(8,n) has been detected by your UART.  Wrong mode
                 settings with fconfigure -mode or a noisy data line (RXD) may
                 cause this error.

       BREAK     A BREAK condition has been detected by your UART (see above).


PORTABILITY ISSUES
       Windows (all versions)
              Valid values for fileName to open(2,3,n) a serial port are of the  form
              comX:,  where  X is a number, generally from 1 to 4.  This nota-
              tion only works for serial ports from 1 to 9, if(3,n) the system hap-
              pens  to  have more than four.  An attempt to open(2,3,n) 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
              \\.\comX, 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.

       Windows NT
              When running Tcl interactively, there may be some strange inter-
              actions  between the real console(4,n), if(3,n) 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(4,n) 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(4,n)  are  not  visible
              until  the the pipe(2,8) 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(4,n) at the same time.   If  the
              command  pipeline  is  started from a script, so that Tcl is not
              accessing the console(4,n), or if(3,n) the command pipeline does  not  use
              standard  input  or output, but is redirected from or to a file(1,n),
              then the above problems do not occur.

       Windows 95
              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(2,8) and  send(2,n)  stan-
              dard output to a pipe(2,8) 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(4,n), if(3,n) 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(4,n) 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(4,n) until the the pipe(2,8)  is
              closed.   These  problems  only  occur  because both Tcl and the
              child application are competing for  the  console(4,n)  at  the  same
              time.  If the command pipeline is started from a script, so that
              Tcl is not accessing the console(4,n), or  if(3,n)  the  command  pipeline
              does not use standard input or output, but is redirected from or
              to a file(1,n), then the above problems do not occur.

              Whether or not Tcl is running interactively, if(3,n) a command  pipe-
              line  is  opened  for reading from a 16-bit DOS application, the
              call to open(2,3,n) will not return until end-of-file has been received
              from the command pipeline's standard output.  If a command pipe-
              line 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(2,8) is actually closed.  This problem occurs because 16-bit DOS
              applications are run synchronously, as described above.

       Macintosh
              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.

       Unix
              Valid values for fileName to open(2,3,n) a serial port are generally of
              the  form  /dev/tty(1,4)X,  where  X  is  a or b, but the name of any
              pseudo-file that maps to a serial port may  be  used.   Advanced
              configuration  options  are only supported for serial ports when
              Tcl is built to use the POSIX serial interface.

              When running Tcl interactively, there may be some strange inter-
              actions  between  the  console(4,n), if(3,n) 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(4,n)
              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(4,n)  at  the
              same time.  If the command pipeline is started from a script, so
              that Tcl is not accessing the console(4,n), or if(3,n) the  command  pipe-
              line does not use standard input, but is redirected from a file(1,n),
              then the above problem does not occur.

       See the PORTABILITY ISSUES section of the exec(3,n,1 builtins) command  for  additional
       information  not specific to command pipelines about executing applica-
       tions on the various platforms


SEE ALSO
       file(1,n)(n),  close(2,7,n)(n),  filename(n),  fconfigure(n),   gets(3,n)(n),   read(2,n,1 builtins)(n),
       puts(3,n)(n), exec(3,n,1 builtins)(n), pid(n), fopen(3)


KEYWORDS
       access(2,5)  mode,  append,  create,  file(1,n), non-blocking, open(2,3,n), permissions,
       pipeline, process, serial



Tcl                                   8.3                              open(2,3,n)(n)

References for this manual (incoming links)