Runtime.runtime.exec() - can't get a batch file to run/output

Hi all,

I’m learning. Be gentle!

I’m trying to use Katalon Studio to execute a test that runs a batch file on my local PC.
I’m using com.kms.katalon.core.configuration.RunConfiguration
The batch file produces a simple report as a text file. The batch file works as expected when I run it directly from my PC, irrespective if I run it via Command line, double-click, or by pasting the full path into the windows Run application.

When I run the test case in Katalon, it executes without error but I don’t receive the expected report.

I think my syntax is correct, because when I change the batch file name to something that doesn’t exist I get The system cannot find the file specified
And, when I try Runtime.runtime.exec("notepad.exe"), notepad opens without a problem.

I’ve tried variations of the following, each with the same result.

Runtime.runtime.exec("C:/<path to batch file>/batch_file.bat");
Runtime.runtime.exec("cmd.exe /C C:/<path to batch file>/batch_file.bat");
Runtime.getRuntime().exec("C:/<path to batch file>/batch_file.bat");
Runtime.getRuntime().exec("cmd.exe /C C:/<path to batch file>/batch_file.bat");

I’ve tried different variations of single/double backslash/forwardslash.
I’ve also tried running Katalon in Administrator mode

Has anyone tried this before?

Yes.

Here is a method I use:

  /**
   * Execute a batch file situated in the KS project directory.
   * @param batchFile (String) e.g. "myfile.bat"
   */
  static void runBatchFile(String batchFile) {
    String bf = RunConfiguration.getProjectDir() + '/' + batchFile
    comment("Running batch file: " + bf)
    Runtime.runtime.exec(bf)
  }

As you can see, I use forward slashes and I don’t use “cmd”.

Because it seems the content of the batch is somehow failing, change it to do something simple:

dir > dir.txt

and look for dir.txt in the project folder.

Thanks Russ,

I’m having no luck with your suggested method either, I’m getting the same result.
The test seems to pass but still no output file.
I tried your dir log test file as the batch file.
I’m convinced I’m dealing with a permissions or versioning issue.

Wrap the code in a try/catch - see if there’s an exception of any kind.

And please double check the project folder for that file.