![](https://csdnimg.cn/release/download_crawler_static/9500557/bg14.jpg)
If standard output has not been redirected then the exec command returns the standard output from the last command in
the pipeline, unless “2>@1” was specified, in which case standard error is included as well. If any of the commands in the
pipeline exit abnormally or are killed or suspended, then exec will return an error and the error message will include the
pipeline's output followed by error messages describing the abnormal terminations; the -errorcode 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 is not redirected and -ignorestderr is not specified, then exec 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.
If the last character of the result or error message is a newline then that character is normally deleted from the result or
error message. This is consistent with other Tcl return values, which do not normally end with newlines. However, if -
keepnewline is specified then the trailing newline is retained.
If standard input is not redirected with “<”, “<<” or “<@” then the standard input for the first command in the pipeline is
taken from the application's current standard input.
If the last arg is “&” then the pipeline will be executed in background. In this case the exec command will return a list whose
elements are the process identifiers for all of the subprocesses in the pipeline. The standard output from the last command in
the pipeline will go to the application's standard output if it has not been redirected, and error output from all of the
commands in the pipeline will go to the application's standard error file unless redirected.
The first word in each command is taken as the command name; tilde-substitution is performed on it, and if the result
contains no slashes then the directories in the PATH environment variable are searched for an executable by the given name.
If the name contains a slash then it must refer to an executable reachable from the current directory. No “glob” expansion or
other shell-like substitutions are performed on the arguments to commands.
PORTABILITY ISSUES
Windows (all versions)
Reading from or writing to a socket, using the “@ fileId” notation, does not work. When reading from a socket, a 16-
bit DOS application will hang and a 32-bit application will return immediately with end-of-file. When either type of
application writes to a socket, the information is instead sent to the console, if one is present, or is discarded.
The Tk console text widget does not provide real standard IO capabilities. Under Tk, when redirecting from standard
input, all applications will see an immediate end-of-file; information redirected to standard output or standard error
will be discarded.
Either forward or backward slashes are accepted as path separators for arguments to Tcl commands. When executing
an application, the path name specified for the application may also contain forward or backward slashes as path
separators. Bear in mind, however, that most Windows applications accept arguments with forward slashes only as
option delimiters and backslashes only in paths. Any arguments to an application that specify a path name with
forward slashes will not automatically be converted to use the backslash character. If an argument contains forward
slashes as the path separator, it may or may not be recognized as a path name, depending on the program.
Additionally, when calling a 16-bit DOS or Windows 3.X application, all path names must use the short, cryptic, path
format (e.g., using “applba~1.def” instead of “applbakery.default”), which can be obtained with the “file attributes
fileName -shortname” command.
Two or more forward or backward slashes in a row in a path refer to a network path. For example, a simple
concatenation of the root directory c:/ with a subdirectory /windows/system will yield c://windows/system (two
slashes together), which refers to the mount point called system on the machine called windows (and the c:/ is
ignored), and is not equivalent to c:/windows/system, which describes a directory on the current computer. The
file join command should be used to concatenate path components.
Note that there are two general types of Win32 console applications:
[1]
CLI — CommandLine Interface, simple stdio exchange. netstat.exe for example.
[2]
TUI — Textmode User Interface, any application that accesses the console API for doing such things as cursor
movement, setting text color, detecting key presses and mouse movement, etc. An example would be
telnet.exe from Windows 2000. These types of applications are not common in a windows environment, but do
exist.