Is there an alternative to Runtime.getRuntime().exec()

折月煮酒 提交于 2019-12-08 17:43:30

问题


Just wondering, if there is something better, newer, safer, faster, etc than Runtime.getRuntime().exec().

I want to run another process from my application on linux, and this is the only way i know how. Would be nice to have an alternative.


回答1:


How about ProcessBuilder?

A bit more:

Introduced in Java 1.5, allows you to gain more control on the process environment - set the working directory, let you redirect the error stream to the input stream (from java POV) and a few more things.

From Oracle's site:

ProcessBuilder - The new ProcessBuilder class provides a more convenient way to invoke subprocesses than does Runtime.exec. In particular, ProcessBuilder makes it easy to start a subprocess with a modified process environment (that is, one based on the parent's process environment, but with a few changes).



来源:https://stackoverflow.com/questions/7069425/is-there-an-alternative-to-runtime-getruntime-exec

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