company logo

BaseContext :: executeShell - Execute action according to file type

The function executes the file passed in (sFilePath) according to the file type, which is associated with the file extension. Usually, the action passed to the shell command in sAction is open, which will open the file according to its extension type. One may, however, pass any other action name and parameters, which are supported by the program called for the file extension. Typical actions are edit, print, browse and find. When the required action is not defined, the call defined as default for the extension is used.

File associations have to be defined in an option section FileAssociations, which has to be provided in the configuration file or via database option settings. The structure of this section is as follows:

FileAssociations

extension default_call

action_name action_call

action_name action_call

...

    extension (section for next extension ...)

    ...

The option hierarchy has three levels, which requires extended ini-file specification or use of xml configuration files, instead.

extension - name of extension (e.g. odt for open office documents)

action_name - name of action to be executed. For a file association, any number of actions may be defined. Typical actions used under Windows are open, print, browse, but any other kind of action may be defined.

action_call, default_call - fuction call for the required action

Action call strings may contain following placeholders:

  • %f - replaced by complete file path
    • %d - replaced by directory path
    • %p - replaced by parameter(s)
  • %a - replaced by action name

The call string may also contain any number of option settings as %option%., which are replaced by appropriate option values before calling the application.

When no action has been passed to the function, the default call as being defined for the extension option is used. The default call is also used, when passing an unknown action. When passing an unknown action and not defining a default call, the function throws an exception.

When the context handle does not refer to a valid context instance the function throws an exception.

FileAssociations  ACCEPT

  odt             libreoffice "%f" %p

    open          libreoffice "%f" %p

    print         libreoffice -p "%f" %p

    to_pdf        libreoffice --invisible --convert-to pdf "%f" %p

Notes:

Under MS Windows, the ShellExecute function will be called, when no appropriate file association has been defined in the options hierarchy. ShellExecute refers to file associations defined in the Windows system.

Implementation overview

Implementation details

  1. Call shell command with action name
    BaseContext  :: executeShell ( odaba::String &sFilePath, odaba::String &sShellAction )

    The action name passed in sAction must be a supported action for the file type shell command. Typically, Open is passed as action name in order to open the file passed in sFilePath with the program associated with the extension.

    • sFilePath - Complete file path
    • sShellAction - Action

      Name of the action to be called. Typical actions are open, print, find, edit and browse.

  2. to list
  3. Call shell command with action and parameter list
    BaseContext  :: executeShell ( odaba::String &sFilePath, odaba::String &sShellAction, odaba::String &sParameter )

    Typically, open is passed as action name in order to open the file passed in sFilePath with the program associated with the extension, but any other action name, which is supported by the associated program, may be passed in sAction. Other typical options are find, print or edit. In addition, several parameters may be passed to the function in sParameter. Parameters passed in the parameter string have to be separated by spaces. Parameters containing spaces have to be quoted.

    • sFilePath - Complete file path
    • sShellAction - Action

      Name of the action to be called. Typical actions are open, print, find, edit and browse.

    • sParameter - Parameter value

      Parameter values allow passing one or more parameters in a parameter string. Usually, parameters are separated by spaces. Parameters containing spaces have to be quoted using double quotes.

  4. to list
  5. Open file with default shell command
    BaseContext  :: executeShell ( odaba::String &sFilePath )

    The file passed in sFilePath will be opened with the program associated with the extension (action open).

    • sFilePath - Complete file path
  6. to list