Running DOS / Batch Commands

Last Updated: 06/07/2018 Introduced in Version: 2.0

Decisions allows you to run commands or batch files using steps in Decisions.  These steps allow you to use all the power of workflow, rules, tasking, alerting, job scheduling, etc. with traditional scripting. 

 

Note: the most important thing you must keep in mind is that all paths and user security are handled on the server where Decisions is running and not on the client where you are doing the design.  Decisions runs as the Local System by default, so all commands and batch files will be run as this user unless you have set up you installation with a different user. 

 

There are two steps that are used to run commands:

Run Command Line Program on File

Found in: Integration > Files

This is a flow step that allows you to run a command that is a design time constant, but it expects a file as the first parameter in the argument string to the command.  For example: c:\temp\runme.bat.

To use this step you need to setup the following properties:

  1. Command: This is the command that will be run. Example “notepad.exe” or “mybatch.bat”.
  2. ParameterString (optional): This is the list of parameters or arguments to pass to the command.

This parameter string, IF it is going to operate on the file configured in this step then the parameter string must use “{0}” to indicate where the file will be passed to the command.

  1. LoadFileOnCompletion: If this is checked then when the command is completed the file will be loaded back into the flow as a result of the flow step.
  2. File: This is a design time constant or runtime variable file to pass to the command to be operated on. This is NOT a file path, but is an actual file. At runtime the contents will be written to a temp file on the server for the command to execute. 

 

Process Start

Found in: Integration / .Net Libraries / System / Diagnostics / Process (Class)

There are two variants of this step:

  1. A Start step with one string input. This step takes a command to run.
  2. A Start step with two string inputs. This step takes a command to run and a list of arguments to pass.

 

This step does not return data to the flow.  If you need to process the results of the command you will need to use additional steps to read in results from a file or other system effected by the command.

 

Example:

In this tutorial we will take a look on the second case (how to run .bat file using Process Start step in Decisions)

The Batch file that we will run in this example looks as following… It take in an argument (which will be a variable with New Folder Name), then it uses this String argument to create a new folder in C:\ directory, and then it copies all files from the constant C:\original folder into newly created folder.

Our C:\original folder that we use in this example as a constant source folder for .bat file looks as following…

In the Decisions Portal we navigate to the Designer Folder and click Create Flow button from Folder Actions Panel.

In the resulting window we name our Flow and click OK to proceed to the Flow Designer.

In the Flow Designer we are going to create a Form for user interactions first. We add Show Form step from Favorite Steps category in the Flow Designer Dialog.

In the resulting pop-up window we Name our Form and click Create to proceed to the Form Designer.

Our Form is designed as following… It has a Label component from the Data category in the ToolBox. Then, it has a TextBox form control from Data category for user to be able to input a name for the new folder that will be created with our .bat file. And finally, it has a Button control from the Actions category in the ToolBox for user to be able to submit the new folder name.. When we finished our Form design we can save it and close Form Designer to return back to our Flow.

Next to our Form Step on the workspace we add System.Diagnostics.Process Start(System.String, System.String) (Method) step from the Integration > All Integrations > .Net Libraries > System > Diagnostics > Process(Class) category.

As mentioned at the beginning of this tutorial, this step requires two inputs to be configured. We select this Step on the workspace and the Edit Step information layer pops up. In this layer, we can configure arguments and file Name inputs for our Step. First we configure arguments field. We choose Select Value [From Flow] Mapping Type and using Path picker we select Folder Name outcome from our Form’s TextBox.

 

Next, for the file Name field, we use Constant Mapping Type and type the path (including file name) to our .bat file into the Value text box.

Then, we connect steps in our Flow as following… This completes our Flow. To test it we can click Debug Flow link on the top panel of the Flow Designer.

 When we debug our Flow, the Form opens first and asks the user for the input. We provide the Form with our input and press Backup on the Form.

Then, our Flow runs to the end with no issues. Our Process Step runs .bat file using our inputs behind the scenes.

To confirm that our Flow executed as we designed we navigate to our C:\ directory and check if the New Folder was created with the Name that we have provided as an input on the Form. We open the New Folder and confirm that all files from the Original Folder were copied to this Folder as we designed.

 

 

Additional Resources