SQUIZZ.com
Loading interface, please wait...
Interface taking a long time to load?
Check your internet connection is up, and you're using the latest app/browser version.

Generic Adaptor (1.0) Adaptor Routine: Run Batch Script

The routine runs a batch script file at a specified location on the file system, and executes each of the operating system commands that exist within the batch script file. By using this routine it effectively allows the Connector to modify different aspects of the operating system, or trigger other software to perform actions. The routine can be scheduled to run on a once off basis, or at a regular intervals, by configuring the Generic adaptor routine to run using the adaptor's routine scheduler.

Topics

  1. Prerequisites
  2. How It Works
  3. Routine Setup: Creating a new Generic HTTP Get Request routine
  4. Routine Setup: Configure Settings
  5. Routine Settings
  6. Routine Message Meanings

Prerequisites

Please make sure you understand how Windows batch script file (.bat file) works, how to create and configure batch script file commands, how Windows user permissions work, and have read the following linked documents before proceeding on.

How It Works

The routine attempts to find a Windows batch script file stored on the file system, and if successfully found the routine will create a Windows process that executes the batch script file, causing the commands within the file to be executed. The routine will pass any arguments across to the batch file, based on routine data fields being created for each arugment, passing the value set within the Source Field column for each routine data field. The source field values combined into a string of arguments to pass to the batch file. It is important that argument values are properly double quote character wrapped when an argument contains any spaces within its value.

When the routine is run from the Data Exports/Routines window, within the Connector's Message Log it will output the results of if the batch file was successfully called, and if not what error occurred. Debug logs will also display the path to the batch file and the string of arguments that were combined together.

When the routine creates the Windows process to execute the batch script file, the Windows process will be run with the same Windows user that the Connector Host Service is being run as, by default that is the Windows "System" user unless the Connector's Host Windows service is configured to run as a different Windows user. This Windows user determines the permissions 

Note that when the batch script file is ran by the routine, if any errors occur within any commands in the batch script file, the Connector will still report that the routine successfully ran. If you wish to have more fine grained messages containing the results of the batch script file commands being run then it's recommended to add into the batch script file the ability to write log messages to dedicated message log file.

Routine steps:

  1. Read through each of the routine data fields and append a list of arguments based on concatenating the source field values together.
  2. Create a Windows process to run the batch script file with.
  3. Pass the batch script file path and the arguments to the Windows process to execute.
  4. Start the process to run the batch script file
  5. The routine logs if the batch script file successfully ran or not within the Connector message logs.

Routine Setup: Creating a new Generic HTTP Get Request routine

  1. Open up the Connector application.
  2. In the Adaptors and Messages tab, Under the Adaptors section, click on the Settings button against a listed Generic adaptor.
  3. Click on the Data Routines tab.
  4. In the Routine Type drop down, select the Run Batch Script File option, then click the Create Routine button.
  5. In the Routine Code text box enter a name for the routine, then press the Save Routine button.

A new routine will be created for the adaptor and appear in the Routines drop down.

Routine Setup: Configure Settings

  1. Click on the Settings tab of the routines.
  2. For each row in the settings table, click on the Setting Value field.
  3. Enter a setting value, then click to the next row. The setting will automatically save once the cursor exits the field.
  4. Click on the Data Fields tab.
  5. Click on the Add Field button to add a data field to the routine for each argument that needs to be passed to the batch script file.
    1. Within Source Field column set the value of the argument. If the value contain spaces then wrap the value with double quote characters.

Notes:

  • In the Routine Settings section below describes what each of the settings does. Use this to configure the routine or read the settings documentation below.
  • If a red icon appears in the Setting Value cell, then the cell does not accept the given input. You will need to change the value in the cell to be valid.

Routine Settings

Below are the settings that can be configured for the routine.

Setting label Allowed Values Description
Batch File Path Allowed Filename Characters

Full file path to where the batch file is located on the file system. Ensure the batch file name contains a .bat file extension. 
Note that the path should not use a mapped network drive unless the Connector's Host Windows Service is configured to run as a Windows user that the mapped network drive is available to. Otherwise use full UNC path to reference a network drive and ensure the Windows "System" user has access to the drive.

Routine Message Meanings

Listed below are a majority of the messages that are generated by the routine, either through the connector logs, or in a scheduled routine email notification.

Type

Message Meaning
Error The adaptor routine was not found or could not be run A error has occurred that has caused the routine not to run as it should. This error occurs when no other errors have been handled. Advised us if this occurs.
Error Unable to run "routine code" due to settings that cannot be found. Please notify us about this issue. The error occurs when the settings for the routine could not be found. This is most likely to do with a update issue when the connector was last changed. Advise us if you see this message.
Error

Batch script file routine: routineLabel failed to execute.

The error occurs when the routine to start the Windows process to run the batch script file but it failed to start. Check that the path to the batch script file is correct. If the batch script file is on a network drive then ensure the file path uses a UNC path instead of a mapped network drive.
Error Batch script file routine: routineLabel successfully executed. The routine successfully was able to to start the Windows process to run the batch script file.
Note that this does not guarentee that any of the commands within the batch script file executed successfully.
Debug Attempting to run batch script file routine The error occurs before the routine attempts to create Windows process for the batch script file to execute. The message displays the list of arguments that it will pass across to the process within the technical message.