ProcessBuilder vs Runtime.exec()

前端 未结 1 1230
被撕碎了的回忆
被撕碎了的回忆 2020-12-17 15:30

Which one is better? By better I mean which one has better security, etc. (not ease of use).

相关标签:
1条回答
  • 2020-12-17 16:20

    Ease of use is the only real difference between those two.

    Note that ease of use can lead to security by helping to avoid mis-use.

    At least on OpenJDK 6 Runtime.exec() is implemented using ProcessBuilder:

    public Process exec(String[] cmdarray, String[] envp, File dir)
        throws IOException {
        return new ProcessBuilder(cmdarray)
            .environment(envp)
            .directory(dir)
            .start();
    }
    
    0 讨论(0)
提交回复
热议问题