I have a problem running a Java process with arguments as a command from another Java manager process. Say I have a main class Main, and I want to pass 0 as an argument (for javaw.exe it's just one of the arguments). To illustrate, if I run something like this in a console, it works:
javaw.exe -X... -D... -cp ... Main 0
This runs Main with the argument 0. Now, to run this from my manager application I use the following line:
Process p = Runtime.getRuntime().exec(new string[] {
"cmd.exe", "/c", "javaw.exe", "-X... -D... -cp ... Main", "0"});
I get the following output in err:
Error: Could not find or load main class 0
In other words, the JVM identifies the 0 as the main class.
Using a different exec overloading is not a recommended option (it's a generic infrastructure).
Well you're passing the whole of "-X... -D... -cp ... Main" as a single argument. Instead, you should have:
Process p = Runtime.getRuntime().exec(new string[] {
"cmd.exe", "/c", "javaw.exe", "-X...", "-D...", "-cp", "...", "Main", "0"});
See more on this question at Stackoverflow