Search code examples
javawindowsprocessbuilder

Java ProcessBuilder and Windows system variables


I want to execute a program within Java with a path that is defined by a custom system variable ("CHROME").

new ProcessBuilder("CHROME").start(); 

Win7: works fine (points to AppData\Local)

Win Vista: does nothing (points to program files)

What do I need to do, to get it running with Vista?


Solution

  • If I understood you correctly, CHROME is a system variable which contains the path to an application. If so, you can try as

    String path = System.getenv("CHROME");
    new ProcessBuilder(path).start(); 
    

    or

    Runtime.getRuntime().exec(path);