Bat files or batch files can be run in selenium, which is pretty straightforward. A batch file is a script file in DOS and windows used to run scripts that consist of multiple commands executed by a command line interpreter.
This article will show how we can run a batch in selenium in that scenario.
String batCommand = "cmd /c start C:\\Users\\arili\\Desktop\\Copy2.bat";
Runtime.getRuntime().exec(batCommand);
- First, we store the command to start a bat file into a string.
- Then runtime execution is opened, and the command to start the bat file is passed within it.
- This runtime will execute the bat file from the path.

- We can see the robust copy command is run from the terminal and its info about the file it copied.
Runtime.getRuntime().exec()
The java runtime exec method executes specific strings in a separate process. This is a method used to invoke files that are present in local.