Can Katalon Test Case run an OS Command?

Is there a way to have Katalon run an Operating System Command? I am running on windows and am testing with a “dir” command. I found this code snippet below:

String cmd = “dir C:\”
dirList = Runtime.getRuntime().exec(cmd)
System.out.println(dirList)

But I get the following error:

Cannot run program “dir”:

Is there a way to accomplish what I’m trying to do?

The below site says you could try:

dirList = Runtime.getRuntime().exec(“cmd /c dir”);

Running Dos/Windows Commands From Java Program | Tech Tutorials (netjstech.com)

1 Like

Thanks for the help grylion54. It put me in the right location to find my answer. What worked for me was the code below:

proc = “cmd /c dir c:\”.execute()
outputStream = new StringBuffer()
proc.waitForProcessOutput(outputStream, System.err)
System.out.println(outputStream.toString())

My output was:

Volume in drive C is Windows
Volume Serial Number is 40F6-46C1
Directory of c:
08/08/2022 01:18 PM Program Files
08/08/2022 08:03 AM Program Files (x86)
08/08/2022 08:02 AM Users
08/08/2022 08:19 AM Windows
06/21/2022 09:10 AM CCleaner_Win10
06/21/2022 09:11 AM Temp
12/07/2019 03:14 AM PerfLogs
08/08/2022 04:46 AM 398 SOCIAccess.log
06/08/2022 08:42 AM _HVD
1 File(s) 398 bytes
8 Dir(s) 80,911,020,032 bytes free