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?
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);
In this question is suggested to run the program from cmd.exe
, ie
new ProcessBuilder("cmd.exe", "%CHROME%");
this should work as long as %CHROME%
is in the environmente that the main Java program passes to the subprocess.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.