68 lines
2.6 KiB
Markdown
Executable file
68 lines
2.6 KiB
Markdown
Executable file
# [b<span style="color:orange">l</span>d](https://rife2.com/bld) Command Line Execution Extension
|
|
|
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
[](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html)
|
|
[](https://rife2.com/bld)
|
|
[](https://repo.rife2.com/#/releases/com/uwyn/rife2/bld-exec)
|
|
[](https://repo.rife2.com/#/snapshots/com/uwyn/rife2/bld-exec)
|
|
[](https://github.com/rife2/bld-exec/actions/workflows/bld.yml)
|
|
|
|
To install the latest version, add the following to the `lib/bld/bld-wrapper.properties` file:
|
|
|
|
```properties
|
|
bld.extension-exec=com.uwyn.rife2:bld-exec
|
|
```
|
|
|
|
For more information, please refer to the [extensions](https://github.com/rife2/bld/wiki/Extensions) documentation.
|
|
|
|
## Execute a Command
|
|
|
|
To execute a command at the command line, add the following to your build file:
|
|
|
|
```java
|
|
@BuildCommand
|
|
public void startServer() throws Exception {
|
|
new ExecOperation()
|
|
.fromProject(this)
|
|
.command("./start.sh", "--port", "8080")
|
|
.execute();
|
|
}
|
|
```
|
|
|
|
## Exit Value
|
|
|
|
Use the `failOnExit` function to specify whether a command non-zero exit value (status) constitutes a failure.
|
|
|
|
```java
|
|
@BuildCommand
|
|
public void startServer() throws Exception {
|
|
final List<String> cmds;
|
|
if (System.getProperty("os.name").toLowerCase().contains("win")) {
|
|
cmds = List.of("cmd", "/c", "stop.bat");
|
|
} else {
|
|
cmds = List.of("./stop.sh");
|
|
}
|
|
new ExecOperation()
|
|
.fromProject(this)
|
|
.command(cmds)
|
|
.failOneExit(false)
|
|
.execute();
|
|
}
|
|
```
|
|
|
|
## Work Directory
|
|
|
|
You can also specify the work directory:
|
|
|
|
```java
|
|
@BuildCommand
|
|
public void startServer() throws Exception {
|
|
new ExecOperation()
|
|
.fromProject(this)
|
|
.command("touch", "foo.txt")
|
|
.workDir(System.getProperty("java.io.tmpdir"))
|
|
.execute();
|
|
}
|
|
```
|
|
|
|
Please check the [ExecOperation documentation](https://rife2.github.io/bld-exec/rife/bld/extension/ExecOperation.html#method-summary) for all available configuration options.
|