Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / man / mann / exec.n
CommitLineData
920dae64
AT
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
219See 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
226Command-Line Name: \\fB\\$1\\fR
227Database Name: \\fB\\$2\\fR
228Database 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
250exec \- Invoke subprocesses
251.SH SYNOPSIS
252\fBexec \fR?\fIswitches\fR? \fIarg \fR?\fIarg ...\fR?
253.BE
254
255.SH DESCRIPTION
256.PP
257This command treats its arguments as the specification
258of one or more subprocesses to execute.
259The arguments take the form of a standard shell pipeline
260where each \fIarg\fR becomes one word of a command, and
261each distinct command becomes a subprocess.
262.PP
263If the initial arguments to \fBexec\fR start with \fB\-\fR then
264they are treated as command-line switches and are not part
265of the pipeline specification. The following switches are
266currently supported:
267.TP 13
268\fB\-keepnewline\fR
269Retains a trailing newline in the pipeline's output.
270Normally a trailing newline will be deleted.
271.TP 13
272\fB\-\|\-\fR
273Marks the end of switches. The argument following this one will
274be treated as the first \fIarg\fR even if it starts with a \fB\-\fR.
275.PP
276If an \fIarg\fR (or pair of \fIarg\fRs) has one of the forms
277described below then it is used by \fBexec\fR to control the
278flow of input and output among the subprocess(es).
279Such arguments will not be passed to the subprocess(es). In forms
280such as ``< \fIfileName\fR'' \fIfileName\fR may either be in a
281separate argument from ``<'' or in the same argument with no
282intervening space (i.e. ``<\fIfileName\fR'').
283.TP 15
284|
285Separates distinct commands in the pipeline. The standard output
286of the preceding command will be piped into the standard input
287of the next command.
288.TP 15
289|&
290Separates distinct commands in the pipeline. Both standard output
291and standard error of the preceding command will be piped into
292the standard input of the next command.
293This form of redirection overrides forms such as 2> and >&.
294.TP 15
295<\0\fIfileName\fR
296The file named by \fIfileName\fR is opened and used as the standard
297input 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
301value from a previous call to \fBopen\fR.
302It 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
309Standard output from the last command is redirected to the file named
310\fIfileName\fR, overwriting its previous contents.
311.TP 15
3122>\0\fIfileName\fR
313Standard error from all commands in the pipeline is redirected to the
314file named \fIfileName\fR, overwriting its previous contents.
315.TP 15
316>&\0\fIfileName\fR
317Both standard output from the last command and standard error from all
318commands are redirected to the file named \fIfileName\fR, overwriting
319its previous contents.
320.TP 15
321>>\0\fIfileName\fR
322Standard output from the last command is
323redirected to the file named \fIfileName\fR, appending to it rather
324than overwriting it.
325.TP 15
3262>>\0\fIfileName\fR
327Standard error from all commands in the pipeline is
328redirected to the file named \fIfileName\fR, appending to it rather
329than overwriting it.
330.TP 15
331>>&\0\fIfileName\fR
332Both standard output from the last command and standard error from
333all commands are redirected to the file named \fIfileName\fR,
334appending 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
338value from a previous call to \fBopen\fR.
339Standard output from the last command is redirected to \fIfileId\fR's
340file, which must have been opened for writing.
341.TP 15
3422>@\0\fIfileId\fR
343\fIFileId\fR must be the identifier for an open file, such as the return
344value from a previous call to \fBopen\fR.
345Standard error from all commands in the pipeline is
346redirected to \fIfileId\fR's file.
347The 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
351value from a previous call to \fBopen\fR.
352Both standard output from the last command and standard error from
353all commands are redirected to \fIfileId\fR's file.
354The file must have been opened for writing.
355.PP
356If standard output has not been redirected then the \fBexec\fR
357command returns the standard output from the last command
358in the pipeline.
359If any of the commands in the pipeline exit abnormally or
360are killed or suspended, then \fBexec\fR will return an error
361and the error message will include the pipeline's output followed by
362error messages describing the abnormal terminations; the
363\fBerrorCode\fR variable will contain additional information
364about the last abnormal termination encountered.
365If any of the commands writes to its standard error file and that
366standard error isn't redirected,
367then \fBexec\fR will return an error; the error message
368will include the pipeline's standard output, followed by messages
369about abnormal terminations (if any), followed by the standard error
370output.
371.PP
372If the last character of the result or error message
373is a newline then that character is normally deleted
374from the result or error message.
375This is consistent with other Tcl return values, which don't
376normally end with newlines.
377However, if \fB\-keepnewline\fR is specified then the trailing
378newline is retained.
379.PP
380If standard input isn't redirected with ``<'' or ``<<''
381or ``<@'' then the standard input for the first command in the
382pipeline is taken from the application's current standard input.
383.PP
384If the last \fIarg\fR is ``&'' then the pipeline will be
385executed in background.
386In this case the \fBexec\fR command will return a list whose
387elements are the process identifiers for all of the subprocesses
388in the pipeline.
389The standard output from the last command in the pipeline will
390go to the application's standard output if it hasn't been
391redirected, and error output from all of
392the commands in the pipeline will go to the application's
393standard error file unless redirected.
394.PP
395The first word in each command is taken as the command name;
396tilde-substitution is performed on it, and if the result contains
397no slashes then the directories
398in the PATH environment variable are searched for
399an executable by the given name.
400If the name contains a slash then it must refer to an executable
401reachable from the current directory.
402No ``glob'' expansion or other shell-like substitutions
403are performed on the arguments to commands.
404
405.VS
406.SH "PORTABILITY ISSUES"
407.TP
408\fBWindows\fR (all versions)
409.
410Reading from or writing to a socket, using the ``\fB@\0\fIfileId\fR''
411notation, does not work. When reading from a socket, a 16-bit DOS
412application will hang and a 32-bit application will return immediately with
413end-of-file. When either type of application writes to a socket, the
414information is instead sent to the console, if one is present, or is
415discarded.
416.sp
417The Tk console text widget does not provide real standard IO capabilities.
418Under Tk, when redirecting from standard input, all applications will see an
419immediate end-of-file; information redirected to standard output or standard
420error will be discarded.
421.sp
422Either forward or backward slashes are accepted as path separators for
423arguments to Tcl commands. When executing an application, the path name
424specified for the application may also contain forward or backward slashes
425as path separators. Bear in mind, however, that most Windows applications
426accept arguments with forward slashes only as option delimiters and
427backslashes only in paths. Any arguments to an application that specify a
428path name with forward slashes will not automatically be converted to use
429the backslash character. If an argument contains forward slashes as the
430path separator, it may or may not be recognized as a path name, depending on
431the program.
432.sp
433Additionally, when calling a 16-bit DOS or Windows 3.X application, all path
434names must use the short, cryptic, path format (e.g., using ``applba~1.def''
435instead of ``applbakery.default''), which can be obtained with the
436\fBfile attributes $fileName -shortname\fR command.
437.sp
438Two or more forward or backward slashes in a row in a path refer to a
439network 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
442point 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,
444which describes a directory on the current computer. The \fBfile join\fR
445command should be used to concatenate path components.
446.sp
447.RS
448Note that there are two general types of Win32 console applications:
449.RS
4501) CLI -- CommandLine Interface, simple stdio exchange. \fBnetstat.exe\fR for
451example.
452.br
4532) TUI -- Textmode User Interface, any application that accesses the console
454API for doing such things as cursor movement, setting text color, detecting
455key presses and mouse movement, etc. An example would be \fBtelnet.exe\fR
456from Windows 2000. These types of applications are not common in a windows
457environment, but do exist.
458.RE
459\fBexec\fR will not work well with TUI applications when a console is not
460present, as is done when launching applications under wish. It is desirable
461to have console applications hidden and detached. This is a designed-in
462limitation as \fBexec\fR wants to communicate over pipes. The Expect
463extension addresses this issue when communicating with a TUI application.
464.sp
465.RE
466.TP
467\fBWindows NT\fR
468.
469When attempting to execute an application, \fBexec\fR first searches for
470the 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
472for the longer name. If a directory name was not specified as part of the
473application name, the following directories are automatically searched in
474order when attempting to locate the application:
475.sp
476.RS
477.RS
478The directory from which the Tcl executable was loaded.
479.br
480The current directory.
481.br
482The Windows NT 32-bit system directory.
483.br
484The Windows NT 16-bit system directory.
485.br
486The Windows NT home directory.
487.br
488The directories listed in the path.
489.RE
490.sp
491In order to execute shell built-in commands like \fBdir\fR and \fBcopy\fR,
492the caller must prepend the desired command with ``\fBcmd.exe /c\0\fR''
493because built-in commands are not implemented using executables.
494.sp
495.RE
496.TP
497\fBWindows 9x\fR
498.
499When attempting to execute an application, \fBexec\fR first searches for
500the 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
502for the longer name. If a directory name was not specified as part of the
503application name, the following directories are automatically searched in
504order when attempting to locate the application:
505.sp
506.RS
507.RS
508The directory from which the Tcl executable was loaded.
509.br
510The current directory.
511.br
512The Windows 9x system directory.
513.br
514The Windows 9x home directory.
515.br
516The directories listed in the path.
517.RE
518.sp
519In order to execute shell built-in commands like \fBdir\fR and \fBcopy\fR,
520the caller must prepend the desired command with ``\fBcommand.com /c\0\fR''
521because built-in commands are not implemented using executables.
522.sp
523Once a 16-bit DOS application has read standard input from a console and
524then quit, all subsequently run 16-bit DOS applications will see the
525standard input as already closed. 32-bit applications do not have this
526problem and will run correctly, even after a 16-bit DOS application thinks
527that standard input is closed. There is no known workaround for this bug
528at this time.
529.sp
530Redirection between the \fBNUL:\fR device and a 16-bit application does not
531always work. When redirecting from \fBNUL:\fR, some applications may hang,
532others will get an infinite stream of ``0x01'' bytes, and some will actually
533correctly get an immediate end-of-file; the behavior seems to depend upon
534something compiled into the application itself. When redirecting greater than
5354K or so to \fBNUL:\fR, some applications will hang. The above problems do not
536happen with 32-bit applications.
537.sp
538All DOS 16-bit applications are run synchronously. All standard input from
539a pipe to a 16-bit DOS application is collected into a temporary file; the
540other end of the pipe must be closed before the 16-bit DOS application
541begins executing. All standard output or error from a 16-bit DOS
542application to a pipe is collected into temporary files; the application
543must terminate before the temporary files are redirected to the next stage
544of the pipeline. This is due to a workaround for a Windows 95 bug in the
545implementation of pipes, and is how the standard Windows 95 DOS shell
546handles pipes itself.
547.sp
548Certain applications, such as \fBcommand.com\fR, should not be executed
549interactively. Applications which directly access the console window,
550rather than reading from their standard input and writing to their standard
551output may fail, hang Tcl, or even hang the system if their own private
552console window is not available to them.
553.RE
554.TP
555\fBMacintosh\fR
556The \fBexec\fR command is not implemented and does not exist under Macintosh.
557.TP
558\fBUnix\fR\0\0\0\0\0\0\0
559The \fBexec\fR command is fully functional and works as described.
560
561.SH "UNIX EXAMPLES"
562Here are some examples of the use of the \fBexec\fR command on Unix.
563.PP
564To execute a simple program and get its result:
565.CS
566\fBexec\fR uname -a
567.CE
568.PP
569To execute a program that can return a non-zero result, you should
570wrap the call to \fBexec\fR in \fBcatch\fR and check what the contents
571of the global \fBerrorCode\fR variable is if you have an error:
572.CS
573set status 0
574if {[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
583When translating a command from a Unix shell invocation, care should
584be taken over the fact that single quote characters have no special
585significance to Tcl. Thus:
586.CS
587awk '{sum += $1} END {print sum}' numbers.list
588.CE
589would be translated into something like:
590.CS
591\fBexec\fR awk {{sum += $1} END {print sum}} numbers.list
592.CE
593.PP
594If you are converting invocations involving shell globbing, you should
595remember that Tcl does not handle globbing or expand things into
596multiple arguments by default. Instead you should write things like
597this:
598.CS
599eval [list \fBexec\fR ls -l] [glob *.tcl]
600.CE
601.PP
602.SH "WINDOWS EXAMPLES"
603Here are some examples of the use of the \fBexec\fR command on Windows.
604.PP
605To start an instance of \fInotepad\fR editing a file without waiting
606for the user to finish editing the file:
607.CS
608\fBexec\fR notepad myfile.txt &
609.CE
610.PP
611To print a text file using \fInotepad\fR:
612.CS
613\fBexec\fR notepad /p myfile.txt
614.CE
615.PP
616If a program calls other programs, such as is common with compilers,
617then you may need to resort to batch files to hide the console windows
618that sometimes pop up:
619.CS
620\fBexec\fR cmp.bat somefile.c -o somefile
621.CE
622With 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
627Sometimes you need to be careful, as different programs may have the
628same name and be in the path. It can then happen that typing a command
629at the DOS prompt finds \fIa different program\fR than the same
630command run via \fBexec\fR. This is because of the (documented)
631differences in behaviour between \fBexec\fR and DOS batch files.
632.PP
633When in doubt, use the command \fBauto_execok\fR: it will return the
634complete path to the program as seen by the \fBexec\fR command. This
635applies especially when you want to run "internal" commands like
636\fIdir\fR from a Tcl script (if you just want to list filenames, use
637the \fBglob\fR command.) To do that, use this:
638.CS
639eval [list \fBexec\fR] [auto_execok dir] [list *.tcl]
640.CE
641
642.SH "SEE ALSO"
643error(n), open(n)
644
645.SH KEYWORDS
646execute, pipeline, redirection, subprocess