Knowledge Base Article

> Knowledge Base > Rapise

Created By  inflectra.adam Monday, August 20, 2018

Sometimes you need to run a  Windows batch file (.BAT) from Rapise. Unlike an executable, you cannot simply use Global.DoLaunch() to execute it since it's not actually an application. This article provides the code you need to use.

When you drag an application .EXE from the Files explorer to the main test script window (MyTest.js), Rapise automatically adds the following code:

     Global.DoLaunch('../../../../../Temp/test.exe');

This works well for executables, but for Windows Batch files (ones ending in .BAT), you need to use a different syntax, as shown below:

  var wsh = new ActiveXObject("WScript.Shell");
  wsh.Run("C:/Temp/test.bat");

This call will launch a batch file and return without waiting for it to finish. If you need to run in synchronously then you need to add a couple of parameters to the call:

  var wsh = new ActiveXObject("WScript.Shell");
  var errCode = wsh.Run("C:/Temp/test.bat", 2, true);

You may see, that we can get process error code in this case.

Please, note. If path to a test file contains space, then full path to your batch file should be enclosed in double quotes like that:

  var wsh = new ActiveXObject("WScript.Shell");
  var errCode = wsh.Run('"C:/Path with Spaces/test.bat"', 2, true);

Also note, that if you refer to the path using %WORKDIR% and it may contain a path then it is saver to use a quote:

  var wsh = new ActiveXObject("WScript.Shell");
  var errCode = wsh.Run('"%WORKDIR%/test.bat"', 2, true);

 

Article Info
  • Last Updated: 8/20/2018
  • Article ID: KB227
  • Views: 1508