ProcessBuilder vs Runtime.exec()

寵の児 提交于 2019-11-27 23:28:11

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/5886829/processbuilder-vs-runtime-exec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!