https://github.com/yegor256/jaxec
Primitive execution of command line commands from Java (mostly useful for tests)
https://github.com/yegor256/jaxec
cli exec java java-library
Last synced: 11 months ago
JSON representation
Primitive execution of command line commands from Java (mostly useful for tests)
- Host: GitHub
- URL: https://github.com/yegor256/jaxec
- Owner: yegor256
- License: mit
- Created: 2023-08-30T13:44:47.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-03-17T15:59:13.000Z (11 months ago)
- Last Synced: 2025-03-17T16:47:46.506Z (11 months ago)
- Topics: cli, exec, java, java-library
- Language: Java
- Homepage:
- Size: 186 KB
- Stars: 13
- Watchers: 3
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Executes Command Line from Java
[](https://www.elegantobjects.org)
[](http://www.rultor.com/p/yegor256/jaxec)
[](https://www.jetbrains.com/idea/)
[](https://github.com/yegor256/jaxec/actions/workflows/mvn.yml)
[](http://www.0pdd.com/p?name=yegor256/jaxec)
[](https://maven-badges.herokuapp.com/maven-central/com.yegor256/jaxec)
[](http://www.javadoc.io/doc/com.yegor256/jaxec)
[](https://codecov.io/gh/yegor256/jaxec)
[](https://hitsofcode.com/view/github/yegor256/jaxec)
[](https://github.com/yegor256/jaxec/blob/master/LICENSE.txt)
It's a simple executor of a shell command from Java. It is essentially
a wrapper around [`Runtime.exec()`][exec], with a fluent interface.
First, you add this to your `pom.xml`:
```xml
com.yegor256
jaxec
0.4.0
```
Then, you use it like this:
```java
import com.yegor256.Jaxec;
String stdout = new Jaxec("ls", "-al")
.with("/tmp") // append argument to the command
.withHome("/home/me") // run it in this directory
.withRedirect(false) // don't redirect STDERR to STDOUT
.withCheck(false) // don't throw if the exit code is not-zero
.withStdin("Hello, world!") // send this text to the STDIN of the command
.exec()
.stdout();
```
If exit code is not equal to zero, a runtime exception
will be thrown by the `exec()` method. You can also use
`unsafeExec()`, which throws checked exception `IOException`.
The stdout and stderr of the command are both sent to Slf4j logging
facility `com.jcabi.log.VerboseProcess`. The level for stdout
is `DEBUG`, while the level for stderr is `WARN`.
## How to Contribute
Fork repository, make changes, send us a
[pull request](https://www.yegor256.com/2014/04/15/github-guidelines.html).
We will review your changes and apply them to the `master` branch shortly,
provided they don't violate our quality standards. To avoid frustration,
before sending us your pull request please run full Maven build:
```bash
mvn clean install -Pqulice
```
You will need Maven 3.3+ and Java 8+.
[exec]: https://docs.oracle.com/javase/8/docs/api/java/lang/Runtime.html#exec-java.lang.String-