OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [doc/] [exec.n] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
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: exec.n,v 1.1.1.1 2002-01-16 10:25:24 markom Exp $
9
'\"
10
.so man.macros
11
.TH exec n 7.6 Tcl "Tcl Built-In Commands"
12
.BS
13
'\" Note:  do not modify the .SH NAME line immediately below!
14
.SH NAME
15
exec \- Invoke subprocess(es)
16
.SH SYNOPSIS
17
\fBexec \fR?\fIswitches\fR? \fIarg \fR?\fIarg ...\fR?
18
.BE
19
 
20
.SH DESCRIPTION
21
.PP
22
This command treats its arguments as the specification
23
of one or more subprocesses to execute.
24
The arguments take the form of a standard shell pipeline
25
where each \fIarg\fR becomes one word of a command, and
26
each distinct command becomes a subprocess.
27
.PP
28
If the initial arguments to \fBexec\fR start with \fB\-\fR then
29
they are treated as command-line switches and are not part
30
of the pipeline specification.  The following switches are
31
currently supported:
32
.TP 13
33
\fB\-keepnewline\fR
34
Retains a trailing newline in the pipeline's output.
35
Normally a trailing newline will be deleted.
36
.TP 13
37
\fB\-\|\-\fR
38
Marks the end of switches.  The argument following this one will
39
be treated as the first \fIarg\fR even if it starts with a \fB\-\fR.
40
.PP
41
If an \fIarg\fR (or pair of \fIarg\fR's) has one of the forms
42
described below then it is used by \fBexec\fR to control the
43
flow of input and output among the subprocess(es).
44
Such arguments will not be passed to the subprocess(es).  In forms
45
such as ``< \fIfileName\fR'' \fIfileName\fR may either be in a
46
separate argument from ``<'' or in the same argument with no
47
intervening space (i.e. ``<\fIfileName\fR'').
48
.TP 15
49
|
50
Separates distinct commands in the pipeline.  The standard output
51
of the preceding command will be piped into the standard input
52
of the next command.
53
.TP 15
54
|&
55
Separates distinct commands in the pipeline.  Both standard output
56
and standard error of the preceding command will be piped into
57
the standard input of the next command.
58
This form of redirection overrides forms such as 2> and >&.
59
.TP 15
60
<\0\fIfileName\fR
61
The file named by \fIfileName\fR is opened and used as the standard
62
input for the first command in the pipeline.
63
.TP 15
64
<@\0\fIfileId\fR
65
\fIFileId\fR must be the identifier for an open file, such as the return
66
value from a previous call to \fBopen\fR.
67
It is used as the standard input for the first command in the pipeline.
68
\fIFileId\fR must have been opened for reading.
69
.TP 15
70
<<\0\fIvalue\fR
71
\fIValue\fR is passed to the first command as its standard input.
72
.TP 15
73
>\0\fIfileName\fR
74
Standard output from the last command is redirected to the file named
75
\fIfileName\fR, overwriting its previous contents.
76
.TP 15
77
2>\0\fIfileName\fR
78
Standard error from all commands in the pipeline is redirected to the
79
file named \fIfileName\fR, overwriting its previous contents.
80
.TP 15
81
>&\0\fIfileName\fR
82
Both standard output from the last command and standard error from all
83
commands are redirected to the file named \fIfileName\fR, overwriting
84
its previous contents.
85
.TP 15
86
>>\0\fIfileName\fR
87
Standard output from the last command is
88
redirected to the file named \fIfileName\fR, appending to it rather
89
than overwriting it.
90
.TP 15
91
2>>\0\fIfileName\fR
92
Standard error from all commands in the pipeline is
93
redirected to the file named \fIfileName\fR, appending to it rather
94
than overwriting it.
95
.TP 15
96
>>&\0\fIfileName\fR
97
Both standard output from the last command and standard error from
98
all commands are redirected to the file named \fIfileName\fR,
99
appending to it rather than overwriting it.
100
.TP 15
101
>@\0\fIfileId\fR
102
\fIFileId\fR must be the identifier for an open file, such as the return
103
value from a previous call to \fBopen\fR.
104
Standard output from the last command is redirected to \fIfileId\fR's
105
file, which must have been opened for writing.
106
.TP 15
107
2>@\0\fIfileId\fR
108
\fIFileId\fR must be the identifier for an open file, such as the return
109
value from a previous call to \fBopen\fR.
110
Standard error from all commands in the pipeline is
111
redirected to \fIfileId\fR's file.
112
The file must have been opened for writing.
113
.TP 15
114
>&@\0\fIfileId\fR
115
\fIFileId\fR must be the identifier for an open file, such as the return
116
value from a previous call to \fBopen\fR.
117
Both standard output from the last command and standard error from
118
all commands are redirected to \fIfileId\fR's file.
119
The file must have been opened for writing.
120
.PP
121
If standard output has not been redirected then the \fBexec\fR
122
command returns the standard output from the last command
123
in the pipeline.
124
If any of the commands in the pipeline exit abnormally or
125
are killed or suspended, then \fBexec\fR will return an error
126
and the error message will include the pipeline's output followed by
127
error messages describing the abnormal terminations; the
128
\fBerrorCode\fR variable will contain additional information
129
about the last abnormal termination encountered.
130
If any of the commands writes to its standard error file and that
131
standard error isn't redirected,
132
then \fBexec\fR will return an error;  the error message
133
will include the pipeline's standard output, followed by messages
134
about abnormal terminations (if any), followed by the standard error
135
output.
136
.PP
137
If the last character of the result or error message
138
is a newline then that character is normally deleted
139
from the result or error message.
140
This is consistent with other Tcl return values, which don't
141
normally end with newlines.
142
However, if \fB\-keepnewline\fR is specified then the trailing
143
newline is retained.
144
.PP
145
If standard input isn't redirected with ``<'' or ``<<''
146
or ``<@'' then the standard input for the first command in the
147
pipeline is taken from the application's current standard input.
148
.PP
149
If the last \fIarg\fR is ``&'' then the pipeline will be
150
executed in background.
151
In this case the \fBexec\fR command will return a list whose
152
elements are the process identifiers for all of the subprocesses
153
in the pipeline.
154
The standard output from the last command in the pipeline will
155
go to the application's standard output if it hasn't been
156
redirected, and error output from all of
157
the commands in the pipeline will go to the application's
158
standard error file unless redirected.
159
.PP
160
The first word in each command is taken as the command name;
161
tilde-substitution is performed on it, and if the result contains
162
no slashes then the directories
163
in the PATH environment variable are searched for
164
an executable by the given name.
165
If the name contains a slash then it must refer to an executable
166
reachable from the current directory.
167
No ``glob'' expansion or other shell-like substitutions
168
are performed on the arguments to commands.
169
 
170
.VS
171
.SH "PORTABILITY ISSUES"
172
.TP
173
\fBWindows\fR (all versions)
174
.
175
Reading from or writing to a socket, using the ``\fB@\0\fIfileId\fR''
176
notation, does not work.  When reading from a socket, a 16-bit DOS
177
application will hang and a 32-bit application will return immediately with
178
end-of-file.  When either type of application writes to a socket, the
179
information is instead sent to the console, if one is present, or is
180
discarded.
181
.sp
182
The Tk console text widget does not provide real standard IO capabilities.
183
Under Tk, when redirecting from standard input, all applications will see an
184
immediate end-of-file; information redirected to standard output or standard
185
error will be discarded.
186
.sp
187
Either forward or backward slashes are accepted as path separators for
188
arguments to Tcl commands.  When executing an application, the path name
189
specified for the application may also contain forward or backward slashes
190
as path separators.  Bear in mind, however, that most Windows applications
191
accept arguments with forward slashes only as option delimiters and
192
backslashes only in paths.  Any arguments to an application that specify a
193
path name with forward slashes will not automatically be converted to use
194
the backslash character.  If an argument contains forward slashes as the
195
path separator, it may or may not be recognized as a path name, depending on
196
the program.
197
.sp
198
Additionally, when calling a 16-bit DOS or Windows 3.X application, all path
199
names must use the short, cryptic, path format (e.g., using ``applba~1.def''
200
instead of ``applbakery.default'').
201
.sp
202
Two or more forward or backward slashes in a row in a path refer to a
203
network path.  For example, a simple concatenation of the root directory
204
\fBc:/\fR with a subdirectory \fB/windows/system\fR will yield
205
\fBc://windows/system\fR (two slashes together), which refers to the
206
directory \fB/system\fR on the machine \fBwindows\fR (and the \fBc:/\fR is
207
ignored), and is not equivalent to \fBc:/windows/system\fR, which describes
208
a directory on the current computer.
209
.TP
210
\fBWindows NT\fR
211
.
212
When attempting to execute an application, \fBexec\fR first searches for the
213
name as it was specified.  Then, in order, \fB.com\fR, \fB.exe\fR, and \fB.bat\fR
214
are appended to the end of the specified name and it searches for
215
the longer name.  If a directory name was not specified as part of the
216
application name, the following directories are automatically searched in
217
order when attempting to locate the application:
218
.sp
219
.RS
220
.RS
221
The directory from which the Tcl executable was loaded.
222
.br
223
The current directory.
224
.br
225
The Windows NT 32-bit system directory.
226
.br
227
The Windows NT 16-bit system directory.
228
.br
229
The Windows NT home directory.
230
.br
231
The directories listed in the path.
232
.RE
233
.sp
234
In order to execute the shell builtin commands like \fBdir\fR and \fBcopy\fR,
235
the caller must prepend ``\fBcmd.exe /c\0\fR'' to the desired command.
236
.sp
237
.RE
238
.TP
239
\fBWindows 95\fR
240
.
241
When attempting to execute an application, \fBexec\fR first searches for the
242
name as it was specified.  Then, in order, \fB.com\fR, \fB.exe\fR, and \fB.bat\fR
243
are appended to the end of the specified name and it searches for
244
the longer name.  If a directory name was not specified as part of the
245
application name, the following directories are automatically searched in
246
order when attempting to locate the application:
247
.sp
248
.RS
249
.RS
250
The directory from which the Tcl executable was loaded.
251
.br
252
The current directory.
253
.br
254
The Windows 95 system directory.
255
.br
256
The Windows 95 home directory.
257
.br
258
The directories listed in the path.
259
.RE
260
.sp
261
In order to execute the shell builtin commands like \fBdir\fR and \fBcopy\fR,
262
the caller must prepend ``\fBcommand.com /c\0\fR'' to the desired command.
263
.sp
264
Once a 16-bit DOS application has read standard input from a console and
265
then quit, all subsequently run 16-bit DOS applications will see the
266
standard input as already closed.  32-bit applications do not have this
267
problem and will run correctly even after a 16-bit DOS application thinks
268
that standard input is closed.  There is no known workaround for this bug
269
at this time.
270
.sp
271
Redirection between the \fBNUL:\fR device and a 16-bit application does not
272
always work.  When redirecting from \fBNUL:\fR, some applications may hang,
273
others will get an infinite stream of ``0x01'' bytes, and some will actually
274
correctly get an immediate end-of-file; the behavior seems to depend upon
275
something compiled into the application itself.  When redirecting greater than
276
4K or so to \fBNUL:\fR, some applications will hang.  The above problems do not
277
happen with 32-bit applications.
278
.sp
279
All DOS 16-bit applications are run synchronously.  All standard input from
280
a pipe to a 16-bit DOS application is collected into a temporary file; the
281
other end of the pipe must be closed before the 16-bit DOS application
282
begins executing.  All standard output or error from a 16-bit DOS
283
application to a pipe is collected into temporary files; the application
284
must terminate before the temporary files are redirected to the next stage
285
of the pipeline.  This is due to a workaround for a Windows 95 bug in the
286
implementation of pipes, and is how the Windows 95 command line interpreter
287
handles pipes itself.
288
.sp
289
Certain applications, such as \fBcommand.com\fR, should not be executed
290
interactively.  Applications which directly access the console window,
291
rather than reading from their standard input and writing to their standard
292
output may fail, hang Tcl, or even hang the system if their own private
293
console window is not available to them.
294
.RE
295
.TP
296
\fBWindows 3.X\fR
297
.
298
When attempting to execute an application, \fBexec\fR first searches for the
299
name as it was specified.  Then, in order, \fB.com\fR, \fB.exe\fR, and \fB.bat\fR
300
are appended to the end of the specified name and it searches for
301
the longer name.  If a directory name was not specified as part of the
302
application name, the following directories are automatically searched in
303
order when attempting to locate the application:
304
.sp
305
.RS
306
.RS
307
The directory from which the Tcl executable was loaded.
308
.br
309
The current directory.
310
.br
311
The Windows 3.X system directory.
312
.br
313
The Windows 3.X home directory.
314
.br
315
The directories listed in the path.
316
.RE
317
.sp
318
In order to execute the shell builtin commands like \fBdir\fR and \fBcopy\fR,
319
the caller must prepend ``\fBcommand.com /c\0\fR'' to the desired command.
320
.sp
321
16-bit and 32-bit DOS and Windows applications may be executed.  However,
322
redirection and piping of standard IO only works with 16-bit DOS
323
applications.  32-bit applications always see standard input as already
324
closed, and any standard output or error is discarded, no matter where in the
325
pipeline the application occurs or what redirection symbols are used by the
326
caller.  Additionally, for 16-bit applications, standard error is always
327
sent to the same place as standard output; it cannot be redirected to a
328
separate location.  In order to achieve pseudo-redirection for 32-bit
329
applications, the 32-bit application must instead be written to take command
330
line arguments that specify the files that it should read from and write to
331
and open those files itself.
332
.sp
333
All applications, both 16-bit and 32-bit, run synchronously; each application
334
runs to completion before the next one in the pipeline starts.  Temporary files
335
are used to simulate piping between applications.  The \fBexec\fR
336
command cannot be used to start an application in the background.
337
.sp
338
When standard input is redirected from an open file using the
339
``\fB@\0\fIfileId\fR'' notation, the open file is completely read up to its
340
end.  This is slightly different than under Windows 95 or NT, where the child
341
application consumes from the open file only as much as it wants.
342
Redirecting to an open file is supported as normal.
343
.RE
344
.TP
345
\fBMacintosh\fR
346
The \fBexec\fR command is not implemented and does not exist under Macintosh.
347
.TP
348
\fBUnix\fR\0\0\0\0\0\0\0
349
The \fBexec\fR command is fully functional and works as described.
350
 
351
.SH "SEE ALSO"
352
open(n)
353
.VE
354
 
355
.SH KEYWORDS
356
execute, pipeline, redirection, subprocess
357
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.