Run Windows Script

Runs Windows scripts in the command line.

Command availability: IBM RPA SaaS and IBM RPA on premises


Runs Windows-type scripts in the command line. For supported types of script, see the scripttype parameter options. You can specify the source of the script in the source parameter options

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

runWindowsScript [--scripttype(WindowsScriptType)] [--source(WindowsScriptSource)] --script(String) --file(String) --asset(String) [--arguments(String)] [--blockexecution(Boolean)] (Numeric)=exitcode (String)=output (String)=error

Input parameters

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Script Type scripttype Optional WindowsScriptType Specifies the type of script to run. For more information, see the scripttype parameter options
Source source Required WindowsScriptSource Select the form in which you want to provide the script. For more information, see the source parameter options. The default value is Text.
Code script Required when Source is Text Text Source code of the script.
File file Required when Source is File Text Path to the file containing the script.
Asset asset Required when Source is Asset Text Name or variable of the asset that contains the script file.
Parameters arguments Optional Text Specifies parameters with values passed to the script.
Block Execution blockexecution Optional Boolean Enable this parameter to block the execution of the current script until the Windows script ends. If this parameter is not enabled, the script does not return any output.

scripttype parameter options

The following types of script are supported:

Script Type Description
BAT Specifies a .BAT type script.
JScript Specifies a JScript type of script. JScript is a variation of JavaScript used in Active Server Pages.
Visual Basic Specifies a Visual Basic type script.
WScript Specifies a Windows Script Host type.

source parameter options

The following sources are supported:

Source Type Description
Text Provide the written command.
Asset Provide the script file as an IBM RPA Studio asset. For more information, see Creating assets.
File Provide the path to the file that contains the script that you want to run.

Output parameters

Designer mode label Script mode name Accepted variable types Description
Exit Code exitcode Number Exit code of the script execution. Only returns a value if the option Block Execution is enabled.
Output output Text Output from the execution of the script. Only returns a value if the option Block Execution is enabled.
Error error Text Error returned if script execution fails. Only returns a value if the option Block Execution is enabled.


The following example creates a folder and an example file in your desktop and runs a Windows Batch file that takes them as parameters. The Batch file copies the file into the folder and attempts to create a new file with the same name as the one in the folder. The program exits with error code 1.

defVar --name desktopPath --type String
defVar --name textWriter --type TextFileWriter
defVar --name myFolder --type String
defVar --name textFilePath --type String
defVar --name exitCode --type Numeric
defVar --name output --type String
defVar --name errorMessage --type String
defVar --name directoryExists --type Boolean
getSpecialFolder --folder "Desktop" desktopPath=value
setVar --name "${textFilePath}" --value "${desktopPath}\\MyTextFile.txt"
setVar --name "${myFolder}" --value "${desktopPath}\\MyFolder"
openTextWriter --mode "OpenOrCreate" --autoflush  --share "None" --path "${textFilePath}" --encoding "Default" textWriter=value
textWrite --text "Hello, World!" --file ${textWriter}
textFileClose --file ${textWriter}
ifFolder --path "${myFolder}" directoryExists=value
if --left "${directoryExists}" --operator "Is_True" --negate
	createDir --path "${myFolder}" myFolder=value
runWindowsScript --scripttype "BATScript" --source "Text" --script "@echo off\r\nrem Copy file to the specified directory\r\nrem Try to create a file with the same name in the directory\r\nrem And get an error level different than 0\r\n\r\ncopy %2 %1\r\necho %errorlevel%\r\ncd %1\r\nfor %%F in (%2) do (\r\n set File=%%~nxF\r\n)\r\nmd %File%\r\necho %errorlevel%\r\nexit /b %errorlevel%\r\n" --arguments "${myFolder} ${textFilePath}" --blockexecution  exitCode=exitcode output=output errorMessage=error
logMessage --message "Output: ${output}\r\nError Message: ${errorMessage}\r\nExit Code: ${exitCode}" --type "Info"

The Block Execution parameter is enabled to output the error messages in the example.