Shell Function

Description

Runs an executable program.

Syntax

Shell(pathname[,windowstyle])

The Shell function syntax has these named-argument parts:

Part

Description

pathname

Name of the program to execute and any required arguments or command line switches; may include directory or folder and drive. May also be the name of a document that has been associated with an executable program.

On the Macintosh, you can use the MacID function to specify an application's signature instead of its name. The following example uses the signature for Microsoft Word:

Shell MacID("MSWD")

windowstyle

Number corresponding to the style of the window in which the program is to be run. In Microsoft Windows, if windowstyle is omitted, the program is started minimized with focus. On the Macintosh (System 7.0 or later), windowstyle only determines whether or not the application gets the focus when it is run.


The windowstyle named argument has these values:

Value

Window Style

1, 5, 9

Normal with focus.

2

Minimized with focus.

3

Maximized with focus.

4,8

Normal without focus.

6,7

Minimized without focus.


Remarks

If you use the MacID function with Shell in Microsoft Windows, an error occurs.

If the Shell function successfully executes the named file, it returns the task identification (ID) of the started program. The task ID is a unique number that identifies the running program. If the Shell function can't start the named program, an error occurs.

Note

The Shell function runs other programs asynchronously. This means you can't depend on a program started with Shell to be finished executing before the statements following the Shell function in your application are executed.

See Also

AppActivate Statement, MacID Function.

Example

This example uses the Shell function to run an application specified by the user. On the Macintosh, using the MacID function ensures that the application can be launched even if the file name of the application has been changed. The Shell function is not available on the Macintosh prior to System 7.0.


' In Microsoft Windows.
' Specifying 1 as the second argument runs the application normally and
' gives it the focus.
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1)    ' Run Calculator.

' On the Macintosh.
' Both statements launch Microsoft Excel.
RetVal = Shell("Microsoft Excel")    ' Specify file name.
RetVal = Shell(MacID("XCEL"))    ' Specify signature.