1<HTML><HEAD><TITLE>Tcl Built-In Commands - open manual page</TITLE></HEAD><BODY>
2<DL>
3<DD><A HREF="open.htm#M2" NAME="L860">NAME</A>
4<DL><DD>open - Open a file-based or command pipeline channel</DL>
5<DD><A HREF="open.htm#M3" NAME="L861">SYNOPSIS</A>
6<DL>
7<DD><B>open </B><I>fileName</I>
8<DD><B>open </B><I>fileName access</I>
9<DD><B>open </B><I>fileName access permissions</I>
10</DL>
11<DD><A HREF="open.htm#M4" NAME="L862">DESCRIPTION</A>
12<DL>
13<DD><A HREF="open.htm#M5" NAME="L863"><B>r</B></A>
14<DD><A HREF="open.htm#M6" NAME="L864"><B>r+</B></A>
15<DD><A HREF="open.htm#M7" NAME="L865"><B>w</B></A>
16<DD><A HREF="open.htm#M8" NAME="L866"><B>w+</B></A>
17<DD><A HREF="open.htm#M9" NAME="L867"><B>a</B></A>
18<DD><A HREF="open.htm#M10" NAME="L868"><B>a+</B></A>
19</DL>
20<DL>
21<DD><A HREF="open.htm#M11" NAME="L869"><B>RDONLY</B></A>
22<DD><A HREF="open.htm#M12" NAME="L870"><B>WRONLY</B></A>
23<DD><A HREF="open.htm#M13" NAME="L871"><B>RDWR</B></A>
24<DD><A HREF="open.htm#M14" NAME="L872"><B>APPEND</B></A>
25<DD><A HREF="open.htm#M15" NAME="L873"><B>CREAT</B></A>
26<DD><A HREF="open.htm#M16" NAME="L874"><B>EXCL</B></A>
27<DD><A HREF="open.htm#M17" NAME="L875"><B>NOCTTY</B></A>
28<DD><A HREF="open.htm#M18" NAME="L876"><B>NONBLOCK</B></A>
29<DD><A HREF="open.htm#M19" NAME="L877"><B>TRUNC</B></A>
30</DL>
31<DD><A HREF="open.htm#M20" NAME="L878">COMMAND PIPELINES</A>
32<DD><A HREF="open.htm#M21" NAME="L879">SERIAL COMMUNICATIONS</A>
33<DL>
34<DD><A HREF="open.htm#M22" NAME="L880"><B>-mode</B> <I>baud</I><B>,</B><I>parity</I><B>,</B><I>data</I><B>,</B><I>stop</I></A>
35<DD><A HREF="open.htm#M23" NAME="L881"><B>-handshake</B> <I>type</I></A>
36<DD><A HREF="open.htm#M24" NAME="L882"><B>-queue</B></A>
37<DD><A HREF="open.htm#M25" NAME="L883"><B>-timeout</B> <I>msec</I></A>
38<DD><A HREF="open.htm#M26" NAME="L884"><B>-ttycontrol</B> <I>{signal boolean signal boolean ...}</I></A>
39<DD><A HREF="open.htm#M27" NAME="L885"><B>-ttystatus</B></A>
40<DD><A HREF="open.htm#M28" NAME="L886"><B>-xchar</B> <I>{xonChar xoffChar}</I></A>
41<DD><A HREF="open.htm#M29" NAME="L887"><B>-pollinterval</B> <I>msec</I></A>
42<DD><A HREF="open.htm#M30" NAME="L888"><B>-sysbuffer</B> <I>inSize</I></A>
43<DD><A HREF="open.htm#M31" NAME="L889"><B>-sysbuffer</B> <I>{inSize outSize}</I></A>
44<DD><A HREF="open.htm#M32" NAME="L890"><B>-lasterror</B></A>
45</DL>
46<DD><A HREF="open.htm#M33" NAME="L891">SERIAL PORT SIGNALS</A>
47<DL>
48<DD><A HREF="open.htm#M34" NAME="L892"><B>TXD(output)</B></A>
49<DD><A HREF="open.htm#M35" NAME="L893"><B>RXD(input)</B></A>
50<DD><A HREF="open.htm#M36" NAME="L894"><B>RTS(output)</B></A>
51<DD><A HREF="open.htm#M37" NAME="L895"><B>CTS(input)</B></A>
52<DD><A HREF="open.htm#M38" NAME="L896"><B>DTR(output)</B></A>
53<DD><A HREF="open.htm#M39" NAME="L897"><B>DSR(input)</B></A>
54<DD><A HREF="open.htm#M40" NAME="L898"><B>DCD(input)</B></A>
55<DD><A HREF="open.htm#M41" NAME="L899"><B>RI(input)</B></A>
56<DD><A HREF="open.htm#M42" NAME="L900"><B>BREAK</B></A>
57</DL>
58<DD><A HREF="open.htm#M43" NAME="L901">ERROR CODES (Windows only)</A>
59<DL>
60<DD><A HREF="open.htm#M44" NAME="L902"><B>RXOVER</B></A>
61<DD><A HREF="open.htm#M45" NAME="L903"><B>TXFULL</B></A>
62<DD><A HREF="open.htm#M46" NAME="L904"><B>OVERRUN</B></A>
63<DD><A HREF="open.htm#M47" NAME="L905"><B>RXPARITY</B></A>
64<DD><A HREF="open.htm#M48" NAME="L906"><B>FRAME</B></A>
65<DD><A HREF="open.htm#M49" NAME="L907"><B>BREAK</B></A>
66</DL>
67<DD><A HREF="open.htm#M50" NAME="L908">PORTABILITY ISSUES</A>
68<DL>
69<DD><A HREF="open.htm#M51" NAME="L909"><B>Windows </B>(all versions)</A>
70<DD><A HREF="open.htm#M52" NAME="L910"><B>Windows NT</B></A>
71<DD><A HREF="open.htm#M53" NAME="L911"><B>Windows 95</B></A>
72<DD><A HREF="open.htm#M54" NAME="L912"><B>Unix</B></A>
73</DL>
74<DD><A HREF="open.htm#M55" NAME="L913">EXAMPLE</A>
75<DD><A HREF="open.htm#M56" NAME="L914">SEE ALSO</A>
76<DD><A HREF="open.htm#M57" NAME="L915">KEYWORDS</A>
77</DL><HR>
78<H3><A NAME="M2">NAME</A></H3>
79open - Open a file-based or command pipeline channel
80<H3><A NAME="M3">SYNOPSIS</A></H3>
81<B>open </B><I>fileName</I><BR>
82<B>open </B><I>fileName access</I><BR>
83<B>open </B><I>fileName access permissions</I><BR>
84<H3><A NAME="M4">DESCRIPTION</A></H3>
85This command opens a file, serial port, or command pipeline and returns a
86channel identifier that may be used in future invocations of commands like
87<B><A HREF="../TclCmd/read.htm">read</A></B>, <B><A HREF="../TclCmd/puts.htm">puts</A></B>, and <B><A HREF="../TclCmd/close.htm">close</A></B>.
88If the first character of <I>fileName</I> is not <B>|</B> then
89the command opens a file:
90<I>fileName</I> gives the name of the file to open, and it must conform to the
91conventions described in the <B><A HREF="../TclCmd/filename.htm">filename</A></B> manual entry.
92<P>
93The <I>access</I> argument, if present, indicates the way in which the file
94(or command pipeline) is to be accessed.
95In the first form <I>access</I> may have any of the following values:
96<P>
97<DL>
98<DT><A NAME="M5"><B>r</B></A><DD>
99Open the file for reading only; the file must already exist. This is the
100default value if <I>access</I> is not specified.
101<P><DT><A NAME="M6"><B>r+</B></A><DD>
102Open the file for both reading and writing; the file must
103already exist.
104<P><DT><A NAME="M7"><B>w</B></A><DD>
105Open the file for writing only.  Truncate it if it exists.  If it doesn't
106exist, create a new file.
107<P><DT><A NAME="M8"><B>w+</B></A><DD>
108Open the file for reading and writing.  Truncate it if it exists.
109If it doesn't exist, create a new file.
110<P><DT><A NAME="M9"><B>a</B></A><DD>
111Open the file for writing only.  If the file doesn't exist,
112create a new empty file.
113Set the file pointer to the end of the file prior to each write.
114<P><DT><A NAME="M10"><B>a+</B></A><DD>
115Open the file for reading and writing.  If the file doesn't exist,
116create a new empty file.
117Set the initial access position  to the end of the file.
118<P></DL>
119<P>
120In the second form, <I>access</I> consists of a list of any of the
121following flags, all of which have the standard POSIX meanings.
122One of the flags must be either <B>RDONLY</B>, <B>WRONLY</B> or <B>RDWR</B>.
123<P>
124<DL>
125<DT><A NAME="M11"><B>RDONLY</B></A><DD>
126Open the file for reading only.
127<P><DT><A NAME="M12"><B>WRONLY</B></A><DD>
128Open the file for writing only.
129<P><DT><A NAME="M13"><B>RDWR</B></A><DD>
130Open the file for both reading and writing.
131<P><DT><A NAME="M14"><B>APPEND</B></A><DD>
132Set the file pointer to the end of the file prior to each write.
133<P><DT><A NAME="M15"><B>CREAT</B></A><DD>
134Create the file if it doesn't already exist (without this flag it
135is an error for the file not to exist).
136<P><DT><A NAME="M16"><B>EXCL</B></A><DD>
137If <B>CREAT</B> is also specified, an error is returned if the
138file already exists.
139<P><DT><A NAME="M17"><B>NOCTTY</B></A><DD>
140If the file is a terminal device, this flag prevents the file from
141becoming the controlling terminal of the process.
142<P><DT><A NAME="M18"><B>NONBLOCK</B></A><DD>
143Prevents the process from blocking while opening the file, and
144possibly in subsequent I/O operations.  The exact behavior of
145this flag is system- and device-dependent;  its use is discouraged
146(it is better to use the <B><A HREF="../TclCmd/fconfigure.htm">fconfigure</A></B> command to put a file
147in nonblocking mode).
148For details refer to your system documentation on the <B>open</B> system
149call's <B>O_NONBLOCK</B> flag.
150<P><DT><A NAME="M19"><B>TRUNC</B></A><DD>
151If the file exists it is truncated to zero length.
152<P></DL>
153<P>
154If a new file is created as part of opening it, <I>permissions</I>
155(an integer) is used to set the permissions for the new file in
156conjunction with the process's file mode creation mask.
157<I>Permissions</I> defaults to 0666.
158<P>
159Note that if you are going to be reading or writing binary data from
160the channel created by this command, you should use the
161<B><A HREF="../TclCmd/fconfigure.htm">fconfigure</A></B> command to change the <B>-translation</B> option of
162the channel to <B><A HREF="../TclCmd/binary.htm">binary</A></B> before transferring any binary data.  This
163is in contrast to the ``b'' character passed as part of the equivalent
164of the <I>access</I> parameter to some versions of the C library
165<I>fopen()</I> function.
166
167<H3><A NAME="M20">COMMAND PIPELINES</A></H3>
168If the first character of <I>fileName</I> is ``|'' then the
169remaining characters of <I>fileName</I> are treated as a list of arguments
170that describe a command pipeline to invoke, in the same style as the
171arguments for <B><A HREF="../TclCmd/exec.htm">exec</A></B>.
172In this case, the channel identifier returned by <B>open</B> may be used
173to write to the command's input pipe or read from its output pipe,
174depending on the value of <I>access</I>.
175If write-only access is used (e.g. <I>access</I> is <B>w</B>), then
176standard output for the pipeline is directed to the current standard
177output unless overridden by the command.
178If read-only access is used (e.g. <I>access</I> is <B>r</B>),
179standard input for the pipeline is taken from the current standard
180input unless overridden by the command.
181The id of the spawned process is accessible through the <B><A HREF="../TclCmd/pid.htm">pid</A></B>
182command, using the channel id returned by <B>open</B> as argument.
183<P>
184If the command (or one of the commands) executed in the command
185pipeline returns an error (according to the definition in <B><A HREF="../TclCmd/exec.htm">exec</A></B>),
186a Tcl error is generated when <B><A HREF="../TclCmd/close.htm">close</A></B> is called on the channel
187unless the pipeline is in non-blocking mode then no exit status is
188returned (a silent <B><A HREF="../TclCmd/close.htm">close</A></B> with -blocking 0).
189<P>
190It is often useful to use the <B><A HREF="../TclCmd/fileevent.htm">fileevent</A></B> command with pipelines
191so other processing may happen at the same time as running the command
192in the background.
193<H3><A NAME="M21">SERIAL COMMUNICATIONS</A></H3>
194If <I>fileName</I> refers to a serial port, then the specified serial port
195is opened and initialized in a platform-dependent manner.  Acceptable
196values for the <I>fileName</I> to use to open a serial port are described in
197the PORTABILITY ISSUES section.
198<P>
199The <B><A HREF="../TclCmd/fconfigure.htm">fconfigure</A></B> command can be used to query and set additional
200configuration options specific to serial ports (where supported):
201<P>
202<DL>
203<DT><A NAME="M22"><B>-mode</B> <I>baud</I><B>,</B><I>parity</I><B>,</B><I>data</I><B>,</B><I>stop</I></A><DD>
204This option is a set of 4 comma-separated values: the baud rate, parity,
205number of data bits, and number of stop bits for this serial port.  The
206<I>baud</I> rate is a simple integer that specifies the connection speed.
207<I>Parity</I> is one of the following letters: <B>n</B>, <B>o</B>, <B>e</B>,
208<B>m</B>, <B>s</B>; respectively signifying the parity options of ``none'',
209``odd'', ``even'', ``mark'', or ``space''.  <I>Data</I> is the number of
210data bits and should be an integer from 5 to 8, while <I>stop</I> is the
211number of stop bits and should be the integer 1 or 2.
212<P><DT><A NAME="M23"><B>-handshake</B> <I>type</I></A><DD>
213(Windows and Unix). This option is used to setup automatic handshake
214control. Note that not all handshake types maybe supported by your operating
215system. The <I>type</I> parameter is case-independent.
216<P>
217If <I>type</I> is <B>none</B> then any handshake is switched off.
218<B>rtscts</B> activates hardware handshake. Hardware handshake signals
219are described below.
220For software handshake <B>xonxoff</B> the handshake characters can be redefined
221with <B>-xchar</B>.
222An additional hardware handshake <B>dtrdsr</B> is available only under Windows.
223There is no default handshake configuration, the initial value depends
224on your operating system settings.
225The <B>-handshake</B> option cannot be queried.
226<P><DT><A NAME="M24"><B>-queue</B></A><DD>
227(Windows and Unix). The <B>-queue</B> option can only be queried.
228It returns a list of two integers representing the current number
229of bytes in the input and output queue respectively.
230<P><DT><A NAME="M25"><B>-timeout</B> <I>msec</I></A><DD>
231(Windows and Unix). This option is used to set the timeout for blocking
232read operations. It specifies the maximum interval between the
233reception of two bytes in milliseconds.
234For Unix systems the granularity is 100 milliseconds.
235The <B>-timeout</B> option does not affect write operations or
236nonblocking reads.
237This option cannot be queried.
238<P><DT><A NAME="M26"><B>-ttycontrol</B> <I>{signal boolean signal boolean ...}</I></A><DD>
239(Windows and Unix). This option is used to setup the handshake
240output lines (see below) permanently or to send a BREAK over the serial line.
241The <I>signal</I> names are case-independent.
242<B>{RTS 1 DTR 0}</B> sets the RTS output to high and the DTR output to low.
243The BREAK condition (see below) is enabled and disabled with <B>{BREAK 1}</B> and
244<B>{BREAK 0}</B> respectively.
245It's not a good idea to change the <B>RTS</B> (or <B>DTR</B>) signal
246with active hardware handshake <B>rtscts</B> (or <B>dtrdsr</B>).
247The result is unpredictable.
248The <B>-ttycontrol</B> option cannot be queried.
249<P><DT><A NAME="M27"><B>-ttystatus</B></A><DD>
250(Windows and Unix). The <B>-ttystatus</B> option can only be
251queried.  It returns the current modem status and handshake input signals
252(see below).
253The result is a list of signal,value pairs with a fixed order,
254e.g. <B>{CTS 1 DSR 0 RING 1 DCD 0}</B>.
255The <I>signal</I> names are returned upper case.
256<P><DT><A NAME="M28"><B>-xchar</B> <I>{xonChar xoffChar}</I></A><DD>
257(Windows and Unix). This option is used to query or change the software
258handshake characters. Normally the operating system default should be
259DC1 (0x11) and DC3 (0x13) representing the ASCII standard
260XON and XOFF characters.
261<P><DT><A NAME="M29"><B>-pollinterval</B> <I>msec</I></A><DD>
262(Windows only). This option is used to set the maximum time between
263polling for fileevents.
264This affects the time interval between checking for events throughout the Tcl
265interpreter (the smallest value always wins).  Use this option only if
266you want to poll the serial port more or less often than 10 msec
267(the default).
268<P><DT><A NAME="M30"><B>-sysbuffer</B> <I>inSize</I></A><DD>
269<P><DT><A NAME="M31"><B>-sysbuffer</B> <I>{inSize outSize}</I></A><DD>
270(Windows only). This option is used to change the size of Windows
271system buffers for a serial channel. Especially at higher communication
272rates the default input buffer size of 4096 bytes can overrun
273for latent systems. The first form specifies the input buffer size,
274in the second form both input and output buffers are defined.
275<P><DT><A NAME="M32"><B>-lasterror</B></A><DD>
276(Windows only). This option is query only.
277In case of a serial communication error, <B><A HREF="../TclCmd/read.htm">read</A></B> or <B><A HREF="../TclCmd/puts.htm">puts</A></B>
278returns a general Tcl file I/O error.
279<B>fconfigure -lasterror</B> can be called to get a list of error details.
280See below for an explanation of the various error codes.
281
282<P></DL>
283<H3><A NAME="M33">SERIAL PORT SIGNALS</A></H3>
284RS-232 is the most commonly used standard electrical interface for serial
285communications. A negative voltage (-3V..-12V) define a mark (on=1) bit and
286a positive voltage (+3..+12V) define a space (off=0) bit (RS-232C).  The
287following signals are specified for incoming and outgoing data, status
288lines and handshaking. Here we are using the terms <I>workstation</I> for
289your computer and <I>modem</I> for the external device, because some signal
290names (DCD, RI) come from modems. Of course your external device may use
291these signal lines for other purposes.
292
293<P>
294<DL>
295<DT><A NAME="M34"><B>TXD(output)</B></A><DD>
296<B>Transmitted Data:</B> Outgoing serial data.
297<P><DT><A NAME="M35"><B>RXD(input)</B></A><DD>
298<B>Received Data:</B>Incoming serial data.
299<P><DT><A NAME="M36"><B>RTS(output)</B></A><DD>
300<B>Request To Send:</B> This hardware handshake line informs the modem that
301your workstation is ready to receive data. Your workstation may
302automatically reset this signal to indicate that the input buffer is full.
303<P><DT><A NAME="M37"><B>CTS(input)</B></A><DD>
304<B>Clear To Send:</B> The complement to RTS. Indicates that the modem is
305ready to receive data.
306<P><DT><A NAME="M38"><B>DTR(output)</B></A><DD>
307<B>Data Terminal Ready:</B> This signal tells the modem that the workstation
308is ready to establish a link. DTR is often enabled automatically whenever a
309serial port is opened.
310<P><DT><A NAME="M39"><B>DSR(input)</B></A><DD>
311<B>Data Set Ready:</B> The complement to DTR. Tells the workstation that the
312modem is ready to establish a link.
313<P><DT><A NAME="M40"><B>DCD(input)</B></A><DD>
314<B>Data Carrier Detect:</B> This line becomes active when a modem detects
315a &quot;Carrier&quot; signal.
316<P><DT><A NAME="M41"><B>RI(input)</B></A><DD>
317<B>Ring Indicator:</B> Goes active when the modem detects an incoming call.
318<P><DT><A NAME="M42"><B>BREAK</B></A><DD>
319A BREAK condition is not a hardware signal line, but a logical zero on the
320TXD or RXD lines for a long period of time, usually 250 to 500
321milliseconds.  Normally a receive or transmit data signal stays at the mark
322(on=1) voltage until the next character is transferred. A BREAK is sometimes
323used to reset the communications line or change the operating mode of
324communications hardware.
325
326<P></DL>
327<H3><A NAME="M43">ERROR CODES (Windows only)</A></H3>
328A lot of different errors may occur during serial read operations or during
329event polling in background. The external device may have been switched
330off, the data lines may be noisy, system buffers may overrun or your mode
331settings may be wrong.  That's why a reliable software should always
332<B><A HREF="../TclCmd/catch.htm">catch</A></B> serial read operations.  In cases of an error Tcl returns a
333general file I/O error.  Then <B>fconfigure -lasterror</B> may help to
334locate the problem.  The following error codes may be returned.
335
336<P>
337<DL>
338<DT><A NAME="M44"><B>RXOVER</B></A><DD>
339Windows input buffer overrun. The data comes faster than your scripts reads
340it or your system is overloaded. Use <B>fconfigure -sysbuffer</B> to avoid a
341temporary bottleneck and/or make your script faster.
342<P><DT><A NAME="M45"><B>TXFULL</B></A><DD>
343Windows output buffer overrun. Complement to RXOVER. This error should
344practically not happen, because Tcl cares about the output buffer status.
345<P><DT><A NAME="M46"><B>OVERRUN</B></A><DD>
346UART buffer overrun (hardware) with data lost.
347The data comes faster than the system driver receives it.
348Check your advanced serial port settings to enable the FIFO (16550) buffer
349and/or setup a lower(1) interrupt threshold value.
350<P><DT><A NAME="M47"><B>RXPARITY</B></A><DD>
351A parity error has been detected by your UART.
352Wrong parity settings with <B>fconfigure -mode</B> or a noisy data line (RXD)
353may cause this error.
354<P><DT><A NAME="M48"><B>FRAME</B></A><DD>
355A stop-bit error has been detected by your UART.
356Wrong mode settings with <B>fconfigure -mode</B> or a noisy data line (RXD)
357may cause this error.
358<P><DT><A NAME="M49"><B>BREAK</B></A><DD>
359A BREAK condition has been detected by your UART (see above).
360
361<P></DL>
362<H3><A NAME="M50">PORTABILITY ISSUES</A></H3>
363<DL>
364<DT><A NAME="M51"><B>Windows </B>(all versions)</A><DD>
365Valid values for <I>fileName</I> to open a serial port are of the form
366<B>com</B><I>X</I><B>:</B>, where <I>X</I> is a number, generally from 1 to 4.
367This notation only works for serial ports from 1 to 9, if the system
368happens to have more than four.  An attempt to open a serial port that
369does not exist or has a number greater than 9 will fail.  An alternate
370form of opening serial ports is to use the filename <B>&#92;&#92;.&#92;comX</B>,
371where X is any number that corresponds to a serial port; please note
372that this method is considerably slower on Windows 95 and Windows 98.
373<P><DT><A NAME="M52"><B>Windows NT</B></A><DD>
374When running Tcl interactively, there may be some strange interactions
375between the real console, if one is present, and a command pipeline that uses
376standard input or output.  If a command pipeline is opened for reading, some
377of the lines entered at the console will be sent to the command pipeline and
378some will be sent to the Tcl evaluator.  If a command pipeline is opened for
379writing, keystrokes entered into the console are not visible until the
380pipe is closed.  This behavior occurs whether the command pipeline is
381executing 16-bit or 32-bit applications.  These problems only occur because
382both Tcl and the child application are competing for the console at
383the same time.  If the command pipeline is started from a script, so that Tcl
384is not accessing the console, or if the command pipeline does not use
385standard input or output, but is redirected from or to a file, then the
386above problems do not occur.
387<P><DT><A NAME="M53"><B>Windows 95</B></A><DD>
388A command pipeline that executes a 16-bit DOS application cannot be opened
389for both reading and writing, since 16-bit DOS applications that receive
390standard input from a pipe and send standard output to a pipe run
391synchronously.  Command pipelines that do not execute 16-bit DOS
392applications run asynchronously and can be opened for both reading and
393writing.
394<P>
395When running Tcl interactively, there may be some strange interactions
396between the real console, if one is present, and a command pipeline that uses
397standard input or output.  If a command pipeline is opened for reading from
398a 32-bit application, some of the keystrokes entered at the console will be
399sent to the command pipeline and some will be sent to the Tcl evaluator.  If
400a command pipeline is opened for writing to a 32-bit application, no output
401is visible on the console until the pipe is closed.  These problems only
402occur because both Tcl and the child application are competing for the
403console at the same time.  If the command pipeline is started from a script,
404so that Tcl is not accessing the console, or if the command pipeline does
405not use standard input or output, but is redirected from or to a file, then
406the above problems do not occur.
407<P>
408Whether or not Tcl is running interactively, if a command pipeline is opened
409for reading from a 16-bit DOS application, the call to <B>open</B> will not
410return until end-of-file has been received from the command pipeline's
411standard output.  If a command pipeline is opened for writing to a 16-bit DOS
412application, no data will be sent to the command pipeline's standard output
413until the pipe is actually closed.  This problem occurs because 16-bit DOS
414applications are run synchronously, as described above.
415<P><DT><A NAME="M54"><B>Unix</B></A><DD>
416Valid values for <I>fileName</I> to open a serial port are generally of the
417form <B>/dev/tty</B><I>X</I>, where <I>X</I> is <B>a</B> or <B>b</B>, but the name
418of any pseudo-file that maps to a serial port may be used.
419Advanced configuration options are only supported for serial ports
420when Tcl is built to use the POSIX serial interface.
421<P>
422When running Tcl interactively, there may be some strange interactions
423between the console, if one is present, and a command pipeline that uses
424standard input.  If a command pipeline is opened for reading, some
425of the lines entered at the console will be sent to the command pipeline and
426some will be sent to the Tcl evaluator.  This problem only occurs because
427both Tcl and the child application are competing for the console at the
428same time.  If the command pipeline is started from a script, so that Tcl is
429not accessing the console, or if the command pipeline does not use standard
430input, but is redirected from a file, then the above problem does not occur.
431<P></DL>
432<P>
433See the PORTABILITY ISSUES section of the <B><A HREF="../TclCmd/exec.htm">exec</A></B> command for additional
434information not specific to command pipelines about executing
435applications on the various platforms
436<H3><A NAME="M55">EXAMPLE</A></H3>
437Open a command pipeline and catch any errors:
438<PRE>set fl [<B>open</B> &quot;| ls this_file_does_not_exist&quot;]
439set data [read $fl]
440if {[catch {close $fl} err]} {
441    puts &quot;ls command failed: $err&quot;
442}</PRE>
443<H3><A NAME="M56">SEE ALSO</A></H3>
444<B><A HREF="../TclCmd/file.htm">file</A></B>, <B><A HREF="../TclCmd/close.htm">close</A></B>, <B><A HREF="../TclCmd/filename.htm">filename</A></B>, <B><A HREF="../TclCmd/fconfigure.htm">fconfigure</A></B>, <B><A HREF="../TclCmd/gets.htm">gets</A></B>, <B><A HREF="../TclCmd/read.htm">read</A></B>, <B><A HREF="../TclCmd/puts.htm">puts</A></B>, <B><A HREF="../TclCmd/exec.htm">exec</A></B>, <B><A HREF="../TclCmd/pid.htm">pid</A></B>, <B>fopen</B>
445<H3><A NAME="M57">KEYWORDS</A></H3>
446<A href="../Keywords/A.htm#access mode">access mode</A>, <A href="../Keywords/A.htm#append">append</A>, <A href="../Keywords/C.htm#create">create</A>, <A href="../Keywords/F.htm#file">file</A>, <A href="../Keywords/N.htm#non-blocking">non-blocking</A>, <A href="../Keywords/O.htm#open">open</A>, <A href="../Keywords/P.htm#permissions">permissions</A>, <A href="../Keywords/P.htm#pipeline">pipeline</A>, <A href="../Keywords/P.htm#process">process</A>, <A href="../Keywords/S.htm#serial">serial</A>
447<HR><PRE>
448<A HREF="../copyright.htm">Copyright</A> &#169; 1993 The Regents of the University of California.
449<A HREF="../copyright.htm">Copyright</A> &#169; 1994-1996 Sun Microsystems, Inc.
450<A HREF="../copyright.htm">Copyright</A> &#169; 1995-1997 Roger E. Critchlow Jr.</PRE>
451</BODY></HTML>
452