10

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
LoudNPossiblyWrong
  • 3,855
  • 7
  • 33
  • 45
  • 1
    Is this way somehow (specifically) insufficient? It sounds like you're just asking for duplicated functionality. – kylc Aug 15 '11 at 19:08
  • java.lang.Process isn't newer. For some purposes it might be better. – bmargulies Aug 15 '11 at 19:09
  • 1
    i am not saying there is anything wrong with getRuntime.exec its just that i learned about it many years ago in java 1.3, it's the only way i know how and was wondering if there is more than one way to skin a cat, thats all. – LoudNPossiblyWrong Aug 15 '11 at 19:17

1 Answers1

14

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

MByD
  • 135,866
  • 28
  • 264
  • 277