[This is preliminary documentation and subject to change]

## #exec

The #exec directive runs a specified application or shell command and sends the output (standard output or ISAPI WriteClient data) to the client browser. You must surround a directive with HTML comment delimiters.

This directive can be used only in STM pages; it cannot be used in ASP pages. There is no matching ASP script method of including the output of multiple CGI scripts or ISAPI applications in a Web page.

###### Syntax

<!-- #exec CommandType= CommandDescription-->

###### Parameters

CommandType

Specifies the type of command. The command type can be one of the following:

Command Type | Meaning
CGI | Runs an application, such as a CGI script, ASP application, or ISAPI application. The CommandDescription parameter is a string that contains the full virtual path of the application, followed by a question mark (?) and any parameters passed to the application. Parameters are separated by plus signs (+). Because running an ISAPI application is only part of processing the SSI document, an ISAPI application is restricted as follows: Any ISAPI extension attempting to send a URL or redirect through the ServerSupportFunction callback function will cause a message to be placed in the HTML stream, but the send-redirect will not be performed. The SSI interpreter (Ssinc.dll) will wait indefinitely for applications returning HSE_STATUS_PENDING unless the ServerSupportFunction is called to finish the session. The ServerSupportFunction is documented at MSDN Library under the ISAPI reference.
CMD | Runs a shell command. The CommandDescription parameter is a string that contains the full, physical path of the shell program, followed by any command-line parameters separated by spaces. If the full path is not specified, the Web server searches the system path. This directive is disabled by default because it poses a security risk to your Web site. To enable it, add a DWORD registry value called SSIEnableCmdDirective to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\W3SVC\Parameters key, and set it to 1. Disable Anonymous Access on any web folder that contains STM files that use the #exec directive. For general information on using the registry, see Registry.

###### Remarks

The file containing this directive must use a file name extension that is mapped to the SSI interpreter; otherwise, the Web server will not process the directive. By default, the file name extensions .stm, .shtm, and .shtml are mapped to the SSI interpreter (ssinc.dll).

An STM page using the #echo directive must be run by itself, or by calling it from an ASP page with Response.Redirect. Calling an STM page from an ASP page with Server.Transfer, Server.Execute, or #include will not work because that would force the STM page to go through asp.dll instead of through ssinc.dll.

If you have the IIS snap-in installed, you can modify default extension mappings and add new mappings; see Setting Application Mappings. Since you cannot map a file extension to more than one executable, you cannot use this directive in ASP files. ASP files are already mapped to the asp.dll and must stay that way.

###### Example

This example uses the CGI command type to run an ASP page, so there is no need to add values to your registry. It would be more efficient to use Server.Execute, Server.Transfer, or #include to run Test.asp from Exec.asp, but here we are just illustrating the #exec directive in an STM file.

--- Exec.asp ---

    <FORM NAME="RunExec" METHOD="POST" ACTION="Exec.asp">
    <INPUT TYPE="SUBMIT" VALUE="Run the #exec Directive" NAME="RunExec">
    </FORM>
    <%
    If Len(Request.Form("RunExec")) Then
      Response.Redirect("Exec.stm")
    End If
    %>

--- Exec.stm ---

    <H3>Inside Exec.stm</H3>
    <!-- #exec CGI="/testfolder/test.asp?test=Hello" -->
    <FORM NAME="Return" METHOD="POST" ACTION="Exec.asp">
    <INPUT TYPE="SUBMIT" VALUE="Return to Previous Page" NAME="Return">
    </FORM>

--- Test.asp ---

    <%
    Response.Write "<BR>Inside Test.asp.<BR>"
    Response.Write "Test = " & Request.QueryString("Test") & ".<BR>"
    %>

© 1997-2001 Microsoft Corporation. All rights reserved.