Run .exe file in Java from file location

You don’t need a console. You can execute a process using a working directory:

exec(String command, String[] envp, File dir)

Executes the specified string command in a separate process
with the specified environment and working directory.

  • command is the location of the .exe
  • envp can be null
  • dir, is the directory of your .exe

With respect to your code it should be…

Runtime.getRuntime().exec("c:\\program files\\test\\test.exe", null, new File("c:\\program files\\test\\"));

Leave a Comment