ShellExecute

Note
This tool is part of the GAMS Tools Library. Please inspect the general information about GAMS Tools.

This allows you to spawn an external program based on the file type of the document to open. If you pass arguments to the external program, then the program together with the argument need to be encapsuled by double quotes. If the arguments contain a double quote this needs to be escaped with a backslash character.

Usage

Command line:

gamstool [win32.]ShellExecute "filename [arguments]" [dir=workdir] [verb=open|edit|find|print|...] [showcmd=0..11]

Compile time:

$callTool [win32.]ShellExecute "filename [arguments]" [dir=workdir] [verb=open|edit|find|print|...] [showcmd=0..11]

Execution time:

executeTool '[win32.]ShellExecute "filename [arguments]" [dir=workdir] [verb=open|edit|find|print|...] [showcmd=0..11]';


Where

Argument Description
filename Name of the file to open.
arguments Additional arguments, if needed.


Argument Description
dir=workdir This specifies the directory where the file to be opened is located. Default: current directory.
verb=open or ... This specifies the action to be performed (default open). The allowed actions are application dependent. Some commonly available verbs include:
  • 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.
  • print: Prints the document file.
  • properties: Displays the object's properties.
-showcmd The optional argument showcmd specifies how an application is to be displayed when it is opened. The map between numerical values 0 to 11 and symbolic names can be found here: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow.

Example: Opening MS Access database

This example uses the [trnsport] model from the model library. After solving the model, a couple of symbols is exported to a Microsoft Access database using GAMS Connect. MS Access is then launched to inspect the results. This is a small example that should run very quickly.

$call.checkErrorLevel gamslib -q trnsport
$call.checkErrorLevel gams trnsport gdx=trnsport.gdx
$onEmbeddedCode Connect:
- GDXReader:
    file: trnsport.gdx
    readAll: True
- SQLWriter:
    connection: {'DRIVER':'Microsoft Access Driver (*.mdb, *.accdb)', 'DBQ': '%system.fp%trnsport.accdb'}
    connectionType: access
    symbols:
      - name: a
        tableName: capacity
        ifExists: replace
      - name: b
        tableName: demand
        ifExists: replace
      - name: d
        tableName: distance
        ifExists: replace
$offEmbeddedCode
$callTool win32.ShellExecute trnsport.accdb

The command $callTool win32.ShellExecute trnsport.accdb will launch Access to view the ACCDB file.