Knowledge Base Article

> Knowledge Base > Rapise

Created By  dmarkovtsev Tuesday, November 7, 2017

In some cases a test needs to run a Windows shell command (e.g. dir, ipconfig, gpresult) and capture/parse output. Learn how to do this in Rapise from this short article.

Rapise has a Global.DoLaunch action which can run executable files with arguments. So to run ipconfig command and redirect result to a file for further analysis use:

Global.DoLaunch('cmd.exe /c "ipconfig > out.txt"');

This statement runs a command ipconfig > out.txt inside Windows command line shell. The shell is closed right after the command is executed because of /cswitch. Here is the full example which gets an IP address from the command output.

var fileName = "out.txt";
Global.DoLaunch('cmd.exe /c "ipconfig > "' + fileName);
Global.DoSleep(1000); // wait a bit for the command to finish and close the output file
var text = File.Read(Global.GetFullPath(fileName));
var m = text.match(/^\s+IPv4[^:]+:\s([^\r]+)/m);
if (m.length > 1)
{
    Log(m[1]); // Prints IP address to the log
}

Some commands have switches that specify an output file path. For example, gpresult has switch /h.

Global.DoLaunch('cmd.exe /c "gpresult /user usr1 /h result.html"');

This statement produces result.html inside the test folder.

Note: Running cmd.exe without /c or /k switch is not a working solution because no new shell window is created when you execute Rapise test in No Debuggingmode.

Article Info
  • Last Updated: 11/7/2017
  • Article ID: KB303
  • Views: 233