Question: I am looking for libraries that I can use to send Unix commands from my Java code. I have already tried Expect4J and Gaynmed, but could not find good documentation with them. My requirements include:

1. Running multiple commands.
2. Capture output for previous command.
3. Take some action/Run different command based on output of last command.

Any pointers will be appreciated.

Answer: 
The [`ProcessBuilder`](http://docs.oracle.com/javase/6/docs/api/java/lang/ProcessBuilder.html) class in the Java standard library supports creating processes and reading their output. You should be able to build it to do what you need, and being in the standard library, it has pretty good documentation.
Is there something wrong with using the `exec()` method?

```
Process p = Runtime.getRuntime().exec("ls -l");

```

You can read from output of this command by doing the following:

```
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));

```