Table of Contents
- March 25, 2004
shellexecute is a small wrapper program for the ShellExecute Windows API call. It allows you to spawn an external program based on the file type of the document to open.
GAMS provides the
execute statement to execute external programs. In some cases we want to let the system figure out what application to start for a given document. This can be accomplished with
shellexecute. For instance, when we call:
Windows will launch the web browser and show
demo.html. This works correctly, irrelevant whether the user installed Microsoft Internet Explorer or Netscape's web browser.
The command line for
shellexecute looks like:
The filename is either a document (e.g.
book1.xls) or an application (e.g.
notepad). If a document is provided, the associated application will be launched. If a directory name is provided the windows explorer will be launched.
If additional parameters are specified they are considered as command line parameters for the process to be spawned.
The following options are recognized:
/verb=vvvSpecifies the action to be performed. The allowed actions are application dependent. Some commonly available verbs include:
verb Description edit Launches an editor and opens the document for editing. find Initiates a search starting from the specified directory. open Launches an application. If this file is not an executable file, its associated application is launched. Prints the document file. properties Displays the object's properties.
/showcmd=flagFlag that specifies how an application is to be displayed when it is opened. The actual behavior is up to the launched program. The possible values are:
showcmd Description SW_HIDE Hides the window and activates another window. SW_MAXIMIZE Maximizes the specified window. SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the $z$-order. SW_RESTORE Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window. SW_SHOW Activates the window and displays it in its current size and position. SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window. SW_SHOWMINIMIZED Activates the window and displays it as a minimized window. SW_SHOWMINNOACTIVE Displays the window as a minimized window. The active window remains active. SW_SHOWNA Displays the window in its current state. The active window remains active. SW_SHOWNOACTIVATE Displays a window in its most recent size and position. The active window remains active. SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
/dir=dddthe default directory for the sub-process.
In many cases you will not need to use any options.
Below are some examples of
ShellExecute. It is noted that much of the behavior is depending on the file associations that are installed on your machine. These file associations can be inspected and changed with the Windows Explorer, see Figure 1.
If a different program is associated with a
.TXT file, a different program will be launched. In my case notepad will be launched due to the file association shown in Figure 1.
The following model is the
trnsport model from the model library. We write the solution both to an HTML file and a CSV file. HTML is standard ASCII and is easily written using the
PUT facility. CSV is even easier, as setting the FILE suffix
csv.pc=5; will automatically generate comma separated values. The web browser is launched to view the HTML file, while Excel will be spawned to view the CSV file.
This example will launch MS Access after exporting a parameter to a MDB file.