简体   繁体   中英

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

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.

How aboutProcessBuilder ?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM