Okay so here is the problem: I have 3 classes MyClass1 and MyClass2 and ExecClass. I go to my command prompt and do this:
$java MyClass1 -exec \"java MyClass
Runtime.exec
, unlike system()
-like functions in other languages, does not invoke a shell to parse the command (and double quoted strings are a shell feature).
To split the string the way you want it, use the Runtime.exec that accepts a String array:
Runtime.getRuntime().exec(new String[] { "java", "MyClass1", "-exec", "java MyClass2 arg1 arg2"});