How to run command lines from Katalon

Hey guys, so right now we are trying to run some tests using Katalon. But part of the test requires us to run a command, via the command line half way through the test.

My question is how do you make Katalon run command lines as part of their test suite?

Right now we are running Katalon from our localhost and our server is an Ubuntu server on AWS.

1 Like

I made a test case as follows. This assumes Windows. This executes “dir” command. You can switch “dir” to any command you like, i think.

import java.lang.ProcessBuilder
import java.lang.Process

File tempDir = new File('C:/temp')
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "dir")
pb.directory(tempDir)
Process process = pb.start()
int ret = process.waitFor()
// print output and err
InputStream is = process.getInputStream()
InputStream es = process.getErrorStream()
WebUI.comment("ret=${ret}")
String line = ""
StringBuilder sb = new StringBuilder()
sb.append(">>>stdout")
BufferedReader rout =
 new BufferedReader(new InputStreamReader(is,"Shift_JIS"));
while ((line = rout.readLine())!= null) {
    sb.append(line + "\n");
}
sb.append(">>>stderr")
BufferedReader rerr =
 new BufferedReader(new InputStreamReader(es,"Shift_JIS"));
while ((line = rerr.readLine())!= null) {
sb.append(line + "\n");
}
WebUI.comment("dir . : ${sb.toString()}")

Hi Garik

You can use the Runtime to execute shell command(s).

def batchFile = 'path/to/your/batchfile.bat'Runtime.runtime.exec(batchFile)