Do not forget that:
means Win32 CreateProcess returns 2 as an error code when it cannot find the specified command; more specifically, when a command does not reference an executable file in a search path.
Runtime.getRuntime().exec() look at this SO question for more complete Runtime.getRuntime().exec() code, as well as this snippet .
This code creates a shell (as in Runtime.getRuntime().exec("cmd /K") ), in which you write to sdtin any command that you want to execute.
An interest in this approach is to reuse the shell process to take advantage of the previous command: you execute " cd ", then execute " dir ", the last command displays the contents of the directory using the cd .
The same would be true for PATH options, just before using javac or java .
source share