Java Runtime.exec() arguments on Linux

后端 未结 1 1070
梦如初夏
梦如初夏 2020-12-21 17:10

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         


        
1条回答
  •  生来不讨喜
    2020-12-21 17:41

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

    0 讨论(0)
提交回复
热议问题