Schifty
Schifty

Reputation: 635

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?

Upvotes: 0

Views: 1129

Answers (2)

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136102

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);

Upvotes: 2

Raffaele
Raffaele

Reputation: 20885

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.

Upvotes: 0

Related Questions