| 1 | '\" |
| 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.6.2.1 2004/10/27 09:35:38 dkf Exp $ |
| 9 | '\" |
| 10 | '\" The definitions below are for supplemental macros used in Tcl/Tk |
| 11 | '\" manual entries. |
| 12 | '\" |
| 13 | '\" .AP type name in/out ?indent? |
| 14 | '\" Start paragraph describing an argument to a library procedure. |
| 15 | '\" type is type of argument (int, etc.), in/out is either "in", "out", |
| 16 | '\" or "in/out" to describe whether procedure reads or modifies arg, |
| 17 | '\" and indent is equivalent to second arg of .IP (shouldn't ever be |
| 18 | '\" needed; use .AS below instead) |
| 19 | '\" |
| 20 | '\" .AS ?type? ?name? |
| 21 | '\" Give maximum sizes of arguments for setting tab stops. Type and |
| 22 | '\" name are examples of largest possible arguments that will be passed |
| 23 | '\" to .AP later. If args are omitted, default tab stops are used. |
| 24 | '\" |
| 25 | '\" .BS |
| 26 | '\" Start box enclosure. From here until next .BE, everything will be |
| 27 | '\" enclosed in one large box. |
| 28 | '\" |
| 29 | '\" .BE |
| 30 | '\" End of box enclosure. |
| 31 | '\" |
| 32 | '\" .CS |
| 33 | '\" Begin code excerpt. |
| 34 | '\" |
| 35 | '\" .CE |
| 36 | '\" End code excerpt. |
| 37 | '\" |
| 38 | '\" .VS ?version? ?br? |
| 39 | '\" Begin vertical sidebar, for use in marking newly-changed parts |
| 40 | '\" of man pages. The first argument is ignored and used for recording |
| 41 | '\" the version when the .VS was added, so that the sidebars can be |
| 42 | '\" found and removed when they reach a certain age. If another argument |
| 43 | '\" is present, then a line break is forced before starting the sidebar. |
| 44 | '\" |
| 45 | '\" .VE |
| 46 | '\" End of vertical sidebar. |
| 47 | '\" |
| 48 | '\" .DS |
| 49 | '\" Begin an indented unfilled display. |
| 50 | '\" |
| 51 | '\" .DE |
| 52 | '\" End of indented unfilled display. |
| 53 | '\" |
| 54 | '\" .SO |
| 55 | '\" Start of list of standard options for a Tk widget. The |
| 56 | '\" options follow on successive lines, in four columns separated |
| 57 | '\" by tabs. |
| 58 | '\" |
| 59 | '\" .SE |
| 60 | '\" End of list of standard options for a Tk widget. |
| 61 | '\" |
| 62 | '\" .OP cmdName dbName dbClass |
| 63 | '\" Start of description of a specific option. cmdName gives the |
| 64 | '\" option's name as specified in the class command, dbName gives |
| 65 | '\" the option's name in the option database, and dbClass gives |
| 66 | '\" the option's class in the option database. |
| 67 | '\" |
| 68 | '\" .UL arg1 arg2 |
| 69 | '\" Print arg1 underlined, then print arg2 normally. |
| 70 | '\" |
| 71 | '\" RCS: @(#) $Id: man.macros,v 1.4 2000/08/25 06:18:32 ericm Exp $ |
| 72 | '\" |
| 73 | '\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages. |
| 74 | .if t .wh -1.3i ^B |
| 75 | .nr ^l \n(.l |
| 76 | .ad b |
| 77 | '\" # Start an argument description |
| 78 | .de AP |
| 79 | .ie !"\\$4"" .TP \\$4 |
| 80 | .el \{\ |
| 81 | . ie !"\\$2"" .TP \\n()Cu |
| 82 | . el .TP 15 |
| 83 | .\} |
| 84 | .ta \\n()Au \\n()Bu |
| 85 | .ie !"\\$3"" \{\ |
| 86 | \&\\$1 \\fI\\$2\\fP (\\$3) |
| 87 | .\".b |
| 88 | .\} |
| 89 | .el \{\ |
| 90 | .br |
| 91 | .ie !"\\$2"" \{\ |
| 92 | \&\\$1 \\fI\\$2\\fP |
| 93 | .\} |
| 94 | .el \{\ |
| 95 | \&\\fI\\$1\\fP |
| 96 | .\} |
| 97 | .\} |
| 98 | .. |
| 99 | '\" # define tabbing values for .AP |
| 100 | .de AS |
| 101 | .nr )A 10n |
| 102 | .if !"\\$1"" .nr )A \\w'\\$1'u+3n |
| 103 | .nr )B \\n()Au+15n |
| 104 | .\" |
| 105 | .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n |
| 106 | .nr )C \\n()Bu+\\w'(in/out)'u+2n |
| 107 | .. |
| 108 | .AS Tcl_Interp Tcl_CreateInterp in/out |
| 109 | '\" # BS - start boxed text |
| 110 | '\" # ^y = starting y location |
| 111 | '\" # ^b = 1 |
| 112 | .de BS |
| 113 | .br |
| 114 | .mk ^y |
| 115 | .nr ^b 1u |
| 116 | .if n .nf |
| 117 | .if n .ti 0 |
| 118 | .if n \l'\\n(.lu\(ul' |
| 119 | .if n .fi |
| 120 | .. |
| 121 | '\" # BE - end boxed text (draw box now) |
| 122 | .de BE |
| 123 | .nf |
| 124 | .ti 0 |
| 125 | .mk ^t |
| 126 | .ie n \l'\\n(^lu\(ul' |
| 127 | .el \{\ |
| 128 | .\" Draw four-sided box normally, but don't draw top of |
| 129 | .\" box if the box started on an earlier page. |
| 130 | .ie !\\n(^b-1 \{\ |
| 131 | \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' |
| 132 | .\} |
| 133 | .el \}\ |
| 134 | \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' |
| 135 | .\} |
| 136 | .\} |
| 137 | .fi |
| 138 | .br |
| 139 | .nr ^b 0 |
| 140 | .. |
| 141 | '\" # VS - start vertical sidebar |
| 142 | '\" # ^Y = starting y location |
| 143 | '\" # ^v = 1 (for troff; for nroff this doesn't matter) |
| 144 | .de VS |
| 145 | .if !"\\$2"" .br |
| 146 | .mk ^Y |
| 147 | .ie n 'mc \s12\(br\s0 |
| 148 | .el .nr ^v 1u |
| 149 | .. |
| 150 | '\" # VE - end of vertical sidebar |
| 151 | .de VE |
| 152 | .ie n 'mc |
| 153 | .el \{\ |
| 154 | .ev 2 |
| 155 | .nf |
| 156 | .ti 0 |
| 157 | .mk ^t |
| 158 | \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n' |
| 159 | .sp -1 |
| 160 | .fi |
| 161 | .ev |
| 162 | .\} |
| 163 | .nr ^v 0 |
| 164 | .. |
| 165 | '\" # Special macro to handle page bottom: finish off current |
| 166 | '\" # box/sidebar if in box/sidebar mode, then invoked standard |
| 167 | '\" # page bottom macro. |
| 168 | .de ^B |
| 169 | .ev 2 |
| 170 | 'ti 0 |
| 171 | 'nf |
| 172 | .mk ^t |
| 173 | .if \\n(^b \{\ |
| 174 | .\" Draw three-sided box if this is the box's first page, |
| 175 | .\" draw two sides but no top otherwise. |
| 176 | .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c |
| 177 | .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c |
| 178 | .\} |
| 179 | .if \\n(^v \{\ |
| 180 | .nr ^x \\n(^tu+1v-\\n(^Yu |
| 181 | \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c |
| 182 | .\} |
| 183 | .bp |
| 184 | 'fi |
| 185 | .ev |
| 186 | .if \\n(^b \{\ |
| 187 | .mk ^y |
| 188 | .nr ^b 2 |
| 189 | .\} |
| 190 | .if \\n(^v \{\ |
| 191 | .mk ^Y |
| 192 | .\} |
| 193 | .. |
| 194 | '\" # DS - begin display |
| 195 | .de DS |
| 196 | .RS |
| 197 | .nf |
| 198 | .sp |
| 199 | .. |
| 200 | '\" # DE - end display |
| 201 | .de DE |
| 202 | .fi |
| 203 | .RE |
| 204 | .sp |
| 205 | .. |
| 206 | '\" # SO - start of list of standard options |
| 207 | .de SO |
| 208 | .SH "STANDARD OPTIONS" |
| 209 | .LP |
| 210 | .nf |
| 211 | .ta 5.5c 11c |
| 212 | .ft B |
| 213 | .. |
| 214 | '\" # SE - end of list of standard options |
| 215 | .de SE |
| 216 | .fi |
| 217 | .ft R |
| 218 | .LP |
| 219 | See the \\fBoptions\\fR manual entry for details on the standard options. |
| 220 | .. |
| 221 | '\" # OP - start of full description for a single option |
| 222 | .de OP |
| 223 | .LP |
| 224 | .nf |
| 225 | .ta 4c |
| 226 | Command-Line Name: \\fB\\$1\\fR |
| 227 | Database Name: \\fB\\$2\\fR |
| 228 | Database Class: \\fB\\$3\\fR |
| 229 | .fi |
| 230 | .IP |
| 231 | .. |
| 232 | '\" # CS - begin code excerpt |
| 233 | .de CS |
| 234 | .RS |
| 235 | .nf |
| 236 | .ta .25i .5i .75i 1i |
| 237 | .. |
| 238 | '\" # CE - end code excerpt |
| 239 | .de CE |
| 240 | .fi |
| 241 | .RE |
| 242 | .. |
| 243 | .de UL |
| 244 | \\$1\l'|0\(ul'\\$2 |
| 245 | .. |
| 246 | .TH exec n 7.6 Tcl "Tcl Built-In Commands" |
| 247 | .BS |
| 248 | '\" Note: do not modify the .SH NAME line immediately below! |
| 249 | .SH NAME |
| 250 | exec \- Invoke subprocesses |
| 251 | .SH SYNOPSIS |
| 252 | \fBexec \fR?\fIswitches\fR? \fIarg \fR?\fIarg ...\fR? |
| 253 | .BE |
| 254 | |
| 255 | .SH DESCRIPTION |
| 256 | .PP |
| 257 | This command treats its arguments as the specification |
| 258 | of one or more subprocesses to execute. |
| 259 | The arguments take the form of a standard shell pipeline |
| 260 | where each \fIarg\fR becomes one word of a command, and |
| 261 | each distinct command becomes a subprocess. |
| 262 | .PP |
| 263 | If the initial arguments to \fBexec\fR start with \fB\-\fR then |
| 264 | they are treated as command-line switches and are not part |
| 265 | of the pipeline specification. The following switches are |
| 266 | currently supported: |
| 267 | .TP 13 |
| 268 | \fB\-keepnewline\fR |
| 269 | Retains a trailing newline in the pipeline's output. |
| 270 | Normally a trailing newline will be deleted. |
| 271 | .TP 13 |
| 272 | \fB\-\|\-\fR |
| 273 | Marks the end of switches. The argument following this one will |
| 274 | be treated as the first \fIarg\fR even if it starts with a \fB\-\fR. |
| 275 | .PP |
| 276 | If an \fIarg\fR (or pair of \fIarg\fRs) has one of the forms |
| 277 | described below then it is used by \fBexec\fR to control the |
| 278 | flow of input and output among the subprocess(es). |
| 279 | Such arguments will not be passed to the subprocess(es). In forms |
| 280 | such as ``< \fIfileName\fR'' \fIfileName\fR may either be in a |
| 281 | separate argument from ``<'' or in the same argument with no |
| 282 | intervening space (i.e. ``<\fIfileName\fR''). |
| 283 | .TP 15 |
| 284 | | |
| 285 | Separates distinct commands in the pipeline. The standard output |
| 286 | of the preceding command will be piped into the standard input |
| 287 | of the next command. |
| 288 | .TP 15 |
| 289 | |& |
| 290 | Separates distinct commands in the pipeline. Both standard output |
| 291 | and standard error of the preceding command will be piped into |
| 292 | the standard input of the next command. |
| 293 | This form of redirection overrides forms such as 2> and >&. |
| 294 | .TP 15 |
| 295 | <\0\fIfileName\fR |
| 296 | The file named by \fIfileName\fR is opened and used as the standard |
| 297 | input for the first command in the pipeline. |
| 298 | .TP 15 |
| 299 | <@\0\fIfileId\fR |
| 300 | \fIFileId\fR must be the identifier for an open file, such as the return |
| 301 | value from a previous call to \fBopen\fR. |
| 302 | It is used as the standard input for the first command in the pipeline. |
| 303 | \fIFileId\fR must have been opened for reading. |
| 304 | .TP 15 |
| 305 | <<\0\fIvalue\fR |
| 306 | \fIValue\fR is passed to the first command as its standard input. |
| 307 | .TP 15 |
| 308 | >\0\fIfileName\fR |
| 309 | Standard output from the last command is redirected to the file named |
| 310 | \fIfileName\fR, overwriting its previous contents. |
| 311 | .TP 15 |
| 312 | 2>\0\fIfileName\fR |
| 313 | Standard error from all commands in the pipeline is redirected to the |
| 314 | file named \fIfileName\fR, overwriting its previous contents. |
| 315 | .TP 15 |
| 316 | >&\0\fIfileName\fR |
| 317 | Both standard output from the last command and standard error from all |
| 318 | commands are redirected to the file named \fIfileName\fR, overwriting |
| 319 | its previous contents. |
| 320 | .TP 15 |
| 321 | >>\0\fIfileName\fR |
| 322 | Standard output from the last command is |
| 323 | redirected to the file named \fIfileName\fR, appending to it rather |
| 324 | than overwriting it. |
| 325 | .TP 15 |
| 326 | 2>>\0\fIfileName\fR |
| 327 | Standard error from all commands in the pipeline is |
| 328 | redirected to the file named \fIfileName\fR, appending to it rather |
| 329 | than overwriting it. |
| 330 | .TP 15 |
| 331 | >>&\0\fIfileName\fR |
| 332 | Both standard output from the last command and standard error from |
| 333 | all commands are redirected to the file named \fIfileName\fR, |
| 334 | appending to it rather than overwriting it. |
| 335 | .TP 15 |
| 336 | >@\0\fIfileId\fR |
| 337 | \fIFileId\fR must be the identifier for an open file, such as the return |
| 338 | value from a previous call to \fBopen\fR. |
| 339 | Standard output from the last command is redirected to \fIfileId\fR's |
| 340 | file, which must have been opened for writing. |
| 341 | .TP 15 |
| 342 | 2>@\0\fIfileId\fR |
| 343 | \fIFileId\fR must be the identifier for an open file, such as the return |
| 344 | value from a previous call to \fBopen\fR. |
| 345 | Standard error from all commands in the pipeline is |
| 346 | redirected to \fIfileId\fR's file. |
| 347 | The file must have been opened for writing. |
| 348 | .TP 15 |
| 349 | >&@\0\fIfileId\fR |
| 350 | \fIFileId\fR must be the identifier for an open file, such as the return |
| 351 | value from a previous call to \fBopen\fR. |
| 352 | Both standard output from the last command and standard error from |
| 353 | all commands are redirected to \fIfileId\fR's file. |
| 354 | The file must have been opened for writing. |
| 355 | .PP |
| 356 | If standard output has not been redirected then the \fBexec\fR |
| 357 | command returns the standard output from the last command |
| 358 | in the pipeline. |
| 359 | If any of the commands in the pipeline exit abnormally or |
| 360 | are killed or suspended, then \fBexec\fR will return an error |
| 361 | and the error message will include the pipeline's output followed by |
| 362 | error messages describing the abnormal terminations; the |
| 363 | \fBerrorCode\fR variable will contain additional information |
| 364 | about the last abnormal termination encountered. |
| 365 | If any of the commands writes to its standard error file and that |
| 366 | standard error isn't redirected, |
| 367 | then \fBexec\fR will return an error; the error message |
| 368 | will include the pipeline's standard output, followed by messages |
| 369 | about abnormal terminations (if any), followed by the standard error |
| 370 | output. |
| 371 | .PP |
| 372 | If the last character of the result or error message |
| 373 | is a newline then that character is normally deleted |
| 374 | from the result or error message. |
| 375 | This is consistent with other Tcl return values, which don't |
| 376 | normally end with newlines. |
| 377 | However, if \fB\-keepnewline\fR is specified then the trailing |
| 378 | newline is retained. |
| 379 | .PP |
| 380 | If standard input isn't redirected with ``<'' or ``<<'' |
| 381 | or ``<@'' then the standard input for the first command in the |
| 382 | pipeline is taken from the application's current standard input. |
| 383 | .PP |
| 384 | If the last \fIarg\fR is ``&'' then the pipeline will be |
| 385 | executed in background. |
| 386 | In this case the \fBexec\fR command will return a list whose |
| 387 | elements are the process identifiers for all of the subprocesses |
| 388 | in the pipeline. |
| 389 | The standard output from the last command in the pipeline will |
| 390 | go to the application's standard output if it hasn't been |
| 391 | redirected, and error output from all of |
| 392 | the commands in the pipeline will go to the application's |
| 393 | standard error file unless redirected. |
| 394 | .PP |
| 395 | The first word in each command is taken as the command name; |
| 396 | tilde-substitution is performed on it, and if the result contains |
| 397 | no slashes then the directories |
| 398 | in the PATH environment variable are searched for |
| 399 | an executable by the given name. |
| 400 | If the name contains a slash then it must refer to an executable |
| 401 | reachable from the current directory. |
| 402 | No ``glob'' expansion or other shell-like substitutions |
| 403 | are performed on the arguments to commands. |
| 404 | |
| 405 | .VS |
| 406 | .SH "PORTABILITY ISSUES" |
| 407 | .TP |
| 408 | \fBWindows\fR (all versions) |
| 409 | . |
| 410 | Reading from or writing to a socket, using the ``\fB@\0\fIfileId\fR'' |
| 411 | notation, does not work. When reading from a socket, a 16-bit DOS |
| 412 | application will hang and a 32-bit application will return immediately with |
| 413 | end-of-file. When either type of application writes to a socket, the |
| 414 | information is instead sent to the console, if one is present, or is |
| 415 | discarded. |
| 416 | .sp |
| 417 | The Tk console text widget does not provide real standard IO capabilities. |
| 418 | Under Tk, when redirecting from standard input, all applications will see an |
| 419 | immediate end-of-file; information redirected to standard output or standard |
| 420 | error will be discarded. |
| 421 | .sp |
| 422 | Either forward or backward slashes are accepted as path separators for |
| 423 | arguments to Tcl commands. When executing an application, the path name |
| 424 | specified for the application may also contain forward or backward slashes |
| 425 | as path separators. Bear in mind, however, that most Windows applications |
| 426 | accept arguments with forward slashes only as option delimiters and |
| 427 | backslashes only in paths. Any arguments to an application that specify a |
| 428 | path name with forward slashes will not automatically be converted to use |
| 429 | the backslash character. If an argument contains forward slashes as the |
| 430 | path separator, it may or may not be recognized as a path name, depending on |
| 431 | the program. |
| 432 | .sp |
| 433 | Additionally, when calling a 16-bit DOS or Windows 3.X application, all path |
| 434 | names must use the short, cryptic, path format (e.g., using ``applba~1.def'' |
| 435 | instead of ``applbakery.default''), which can be obtained with the |
| 436 | \fBfile attributes $fileName -shortname\fR command. |
| 437 | .sp |
| 438 | Two or more forward or backward slashes in a row in a path refer to a |
| 439 | network path. For example, a simple concatenation of the root directory |
| 440 | \fBc:/\fR with a subdirectory \fB/windows/system\fR will yield |
| 441 | \fBc://windows/system\fR (two slashes together), which refers to the mount |
| 442 | point called \fBsystem\fR on the machine called \fBwindows\fR (and the |
| 443 | \fBc:/\fR is ignored), and is not equivalent to \fBc:/windows/system\fR, |
| 444 | which describes a directory on the current computer. The \fBfile join\fR |
| 445 | command should be used to concatenate path components. |
| 446 | .sp |
| 447 | .RS |
| 448 | Note that there are two general types of Win32 console applications: |
| 449 | .RS |
| 450 | 1) CLI -- CommandLine Interface, simple stdio exchange. \fBnetstat.exe\fR for |
| 451 | example. |
| 452 | .br |
| 453 | 2) TUI -- Textmode User Interface, any application that accesses the console |
| 454 | API for doing such things as cursor movement, setting text color, detecting |
| 455 | key presses and mouse movement, etc. An example would be \fBtelnet.exe\fR |
| 456 | from Windows 2000. These types of applications are not common in a windows |
| 457 | environment, but do exist. |
| 458 | .RE |
| 459 | \fBexec\fR will not work well with TUI applications when a console is not |
| 460 | present, as is done when launching applications under wish. It is desirable |
| 461 | to have console applications hidden and detached. This is a designed-in |
| 462 | limitation as \fBexec\fR wants to communicate over pipes. The Expect |
| 463 | extension addresses this issue when communicating with a TUI application. |
| 464 | .sp |
| 465 | .RE |
| 466 | .TP |
| 467 | \fBWindows NT\fR |
| 468 | . |
| 469 | When attempting to execute an application, \fBexec\fR first searches for |
| 470 | the name as it was specified. Then, in order, \fB.com\fR, \fB.exe\fR, and |
| 471 | \fB.bat\fR are appended to the end of the specified name and it searches |
| 472 | for the longer name. If a directory name was not specified as part of the |
| 473 | application name, the following directories are automatically searched in |
| 474 | order when attempting to locate the application: |
| 475 | .sp |
| 476 | .RS |
| 477 | .RS |
| 478 | The directory from which the Tcl executable was loaded. |
| 479 | .br |
| 480 | The current directory. |
| 481 | .br |
| 482 | The Windows NT 32-bit system directory. |
| 483 | .br |
| 484 | The Windows NT 16-bit system directory. |
| 485 | .br |
| 486 | The Windows NT home directory. |
| 487 | .br |
| 488 | The directories listed in the path. |
| 489 | .RE |
| 490 | .sp |
| 491 | In order to execute shell built-in commands like \fBdir\fR and \fBcopy\fR, |
| 492 | the caller must prepend the desired command with ``\fBcmd.exe /c\0\fR'' |
| 493 | because built-in commands are not implemented using executables. |
| 494 | .sp |
| 495 | .RE |
| 496 | .TP |
| 497 | \fBWindows 9x\fR |
| 498 | . |
| 499 | When attempting to execute an application, \fBexec\fR first searches for |
| 500 | the name as it was specified. Then, in order, \fB.com\fR, \fB.exe\fR, and |
| 501 | \fB.bat\fR are appended to the end of the specified name and it searches |
| 502 | for the longer name. If a directory name was not specified as part of the |
| 503 | application name, the following directories are automatically searched in |
| 504 | order when attempting to locate the application: |
| 505 | .sp |
| 506 | .RS |
| 507 | .RS |
| 508 | The directory from which the Tcl executable was loaded. |
| 509 | .br |
| 510 | The current directory. |
| 511 | .br |
| 512 | The Windows 9x system directory. |
| 513 | .br |
| 514 | The Windows 9x home directory. |
| 515 | .br |
| 516 | The directories listed in the path. |
| 517 | .RE |
| 518 | .sp |
| 519 | In order to execute shell built-in commands like \fBdir\fR and \fBcopy\fR, |
| 520 | the caller must prepend the desired command with ``\fBcommand.com /c\0\fR'' |
| 521 | because built-in commands are not implemented using executables. |
| 522 | .sp |
| 523 | Once a 16-bit DOS application has read standard input from a console and |
| 524 | then quit, all subsequently run 16-bit DOS applications will see the |
| 525 | standard input as already closed. 32-bit applications do not have this |
| 526 | problem and will run correctly, even after a 16-bit DOS application thinks |
| 527 | that standard input is closed. There is no known workaround for this bug |
| 528 | at this time. |
| 529 | .sp |
| 530 | Redirection between the \fBNUL:\fR device and a 16-bit application does not |
| 531 | always work. When redirecting from \fBNUL:\fR, some applications may hang, |
| 532 | others will get an infinite stream of ``0x01'' bytes, and some will actually |
| 533 | correctly get an immediate end-of-file; the behavior seems to depend upon |
| 534 | something compiled into the application itself. When redirecting greater than |
| 535 | 4K or so to \fBNUL:\fR, some applications will hang. The above problems do not |
| 536 | happen with 32-bit applications. |
| 537 | .sp |
| 538 | All DOS 16-bit applications are run synchronously. All standard input from |
| 539 | a pipe to a 16-bit DOS application is collected into a temporary file; the |
| 540 | other end of the pipe must be closed before the 16-bit DOS application |
| 541 | begins executing. All standard output or error from a 16-bit DOS |
| 542 | application to a pipe is collected into temporary files; the application |
| 543 | must terminate before the temporary files are redirected to the next stage |
| 544 | of the pipeline. This is due to a workaround for a Windows 95 bug in the |
| 545 | implementation of pipes, and is how the standard Windows 95 DOS shell |
| 546 | handles pipes itself. |
| 547 | .sp |
| 548 | Certain applications, such as \fBcommand.com\fR, should not be executed |
| 549 | interactively. Applications which directly access the console window, |
| 550 | rather than reading from their standard input and writing to their standard |
| 551 | output may fail, hang Tcl, or even hang the system if their own private |
| 552 | console window is not available to them. |
| 553 | .RE |
| 554 | .TP |
| 555 | \fBMacintosh\fR |
| 556 | The \fBexec\fR command is not implemented and does not exist under Macintosh. |
| 557 | .TP |
| 558 | \fBUnix\fR\0\0\0\0\0\0\0 |
| 559 | The \fBexec\fR command is fully functional and works as described. |
| 560 | |
| 561 | .SH "UNIX EXAMPLES" |
| 562 | Here are some examples of the use of the \fBexec\fR command on Unix. |
| 563 | .PP |
| 564 | To execute a simple program and get its result: |
| 565 | .CS |
| 566 | \fBexec\fR uname -a |
| 567 | .CE |
| 568 | .PP |
| 569 | To execute a program that can return a non-zero result, you should |
| 570 | wrap the call to \fBexec\fR in \fBcatch\fR and check what the contents |
| 571 | of the global \fBerrorCode\fR variable is if you have an error: |
| 572 | .CS |
| 573 | set status 0 |
| 574 | if {[catch {\fBexec\fR grep foo bar.txt} results]} { |
| 575 | if {[lindex $::errorCode 0] eq "CHILDSTATUS"} { |
| 576 | set status [lindex $::errorCode 2] |
| 577 | } else { |
| 578 | # Some kind of unexpected failure |
| 579 | } |
| 580 | } |
| 581 | .CE |
| 582 | .PP |
| 583 | When translating a command from a Unix shell invocation, care should |
| 584 | be taken over the fact that single quote characters have no special |
| 585 | significance to Tcl. Thus: |
| 586 | .CS |
| 587 | awk '{sum += $1} END {print sum}' numbers.list |
| 588 | .CE |
| 589 | would be translated into something like: |
| 590 | .CS |
| 591 | \fBexec\fR awk {{sum += $1} END {print sum}} numbers.list |
| 592 | .CE |
| 593 | .PP |
| 594 | If you are converting invocations involving shell globbing, you should |
| 595 | remember that Tcl does not handle globbing or expand things into |
| 596 | multiple arguments by default. Instead you should write things like |
| 597 | this: |
| 598 | .CS |
| 599 | eval [list \fBexec\fR ls -l] [glob *.tcl] |
| 600 | .CE |
| 601 | .PP |
| 602 | .SH "WINDOWS EXAMPLES" |
| 603 | Here are some examples of the use of the \fBexec\fR command on Windows. |
| 604 | .PP |
| 605 | To start an instance of \fInotepad\fR editing a file without waiting |
| 606 | for the user to finish editing the file: |
| 607 | .CS |
| 608 | \fBexec\fR notepad myfile.txt & |
| 609 | .CE |
| 610 | .PP |
| 611 | To print a text file using \fInotepad\fR: |
| 612 | .CS |
| 613 | \fBexec\fR notepad /p myfile.txt |
| 614 | .CE |
| 615 | .PP |
| 616 | If a program calls other programs, such as is common with compilers, |
| 617 | then you may need to resort to batch files to hide the console windows |
| 618 | that sometimes pop up: |
| 619 | .CS |
| 620 | \fBexec\fR cmp.bat somefile.c -o somefile |
| 621 | .CE |
| 622 | With the file \fIcmp.bat\fR looking something like: |
| 623 | .CS |
| 624 | @gcc %1 %2 %3 %4 %5 %6 %7 %8 %9 |
| 625 | .CE |
| 626 | .PP |
| 627 | Sometimes you need to be careful, as different programs may have the |
| 628 | same name and be in the path. It can then happen that typing a command |
| 629 | at the DOS prompt finds \fIa different program\fR than the same |
| 630 | command run via \fBexec\fR. This is because of the (documented) |
| 631 | differences in behaviour between \fBexec\fR and DOS batch files. |
| 632 | .PP |
| 633 | When in doubt, use the command \fBauto_execok\fR: it will return the |
| 634 | complete path to the program as seen by the \fBexec\fR command. This |
| 635 | applies especially when you want to run "internal" commands like |
| 636 | \fIdir\fR from a Tcl script (if you just want to list filenames, use |
| 637 | the \fBglob\fR command.) To do that, use this: |
| 638 | .CS |
| 639 | eval [list \fBexec\fR] [auto_execok dir] [list *.tcl] |
| 640 | .CE |
| 641 | |
| 642 | .SH "SEE ALSO" |
| 643 | error(n), open(n) |
| 644 | |
| 645 | .SH KEYWORDS |
| 646 | execute, pipeline, redirection, subprocess |