I am interested if anyone has an idea on how to run unix commands without using runtime or ProcessBuilder in a java application
Class ProcessBuilder. This class is used to create operating system processes. Each ProcessBuilder instance manages a collection of process attributes. The start() method creates a new Process instance with those attributes.
The ProcessBuilder Class Note that ProcessBuilder is not a synchronized class; hence, if it is not synchronized explicitly, it not thread safe to access the instance of this class through multiple threads.
ProcessBuilder. directory(File directory) method sets this process builder's working directory. Subprocesses subsequently started by this object's start() method will use this as their working directory.
Well you can use DefaultExecutor from Apache Commons Exec library to execute commands but it internally uses java.lang.Runtime
and java.lang.Process
.
I would suggest you to use this library over Runtime because Apache Command Execution APIs are more sophisticated, and provide all and more features than Java Runtime. It also handles exit Values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With