1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
-
+
|
'\"
'\" 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.
'\"
'\" RCS: @(#) $Id: exec.n,v 1.6.4.4 2004/10/28 18:46:13 dgp Exp $
'\" RCS: @(#) $Id: exec.n,v 1.6.4.5 2004/12/09 23:00:28 dgp Exp $
'\"
.so man.macros
.TH exec n 8.5 Tcl "Tcl Built-In Commands"
.BS
'\" Note: do not modify the .SH NAME line immediately below!
.SH NAME
exec \- Invoke subprocesses
|
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
-
+
|
unless ``2>@1'' was specified, in which case
standard error is included as well.
.VE 8.5
If any of the commands in the pipeline exit abnormally or
are killed or suspended, then \fBexec\fR will return an error
and the error message will include the pipeline's output followed by
error messages describing the abnormal terminations; the
\fBerrorCode\fR variable will contain additional information
\fB-errorcode\fR return option will contain additional information
about the last abnormal termination encountered.
If any of the commands writes to its standard error file and that
standard error isn't redirected,
then \fBexec\fR will return an error; the error message
will include the pipeline's standard output, followed by messages
about abnormal terminations (if any), followed by the standard error
output.
|
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
-
-
+
+
-
-
-
+
+
+
+
|
.PP
To execute a simple program and get its result:
.CS
\fBexec\fR uname -a
.CE
.PP
To execute a program that can return a non-zero result, you should
wrap the call to \fBexec\fR in \fBcatch\fR and check what the contents
of the global \fBerrorCode\fR variable is if you have an error:
wrap the call to \fBexec\fR in \fBcatch\fR and check the contents
of the \fB-errorcode\fR return option if you have an error:
.CS
set status 0
if {[catch {\fBexec\fR grep foo bar.txt} results]} {
if {[lindex $::errorCode 0] eq "CHILDSTATUS"} {
set status [lindex $::errorCode 2]
if {[catch {\fBexec\fR grep foo bar.txt} results options]} {
set details [dict get $options -errorcode]
if {[lindex $details 0] eq "CHILDSTATUS"} {
set status [lindex $details 2]
} else {
# Some kind of unexpected failure
}
}
.CE
.PP
When translating a command from a Unix shell invocation, care should
|