win-exec


License

License

GroupId

GroupId

io.webfolder
ArtifactId

ArtifactId

win-exec
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

win-exec
win-exec
Project URL

Project URL

https://github.com/webfolderio/win-exec
Source Code Management

Source Code Management

https://github.com/webfolderio/win-exec.git

Download win-exec

How to add to project

<!-- https://jarcasting.com/artifacts/io.webfolder/win-exec/ -->
<dependency>
    <groupId>io.webfolder</groupId>
    <artifactId>win-exec</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.webfolder/win-exec/
implementation 'io.webfolder:win-exec:1.0.0'
// https://jarcasting.com/artifacts/io.webfolder/win-exec/
implementation ("io.webfolder:win-exec:1.0.0")
'io.webfolder:win-exec:jar:1.0.0'
<dependency org="io.webfolder" name="win-exec" rev="1.0.0">
  <artifact name="win-exec" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.webfolder', module='win-exec', version='1.0.0')
)
libraryDependencies += "io.webfolder" % "win-exec" % "1.0.0"
[io.webfolder/win-exec "1.0.0"]

Dependencies

test (4)

Group / Artifact Type Version
org.zeroturnaround : zt-zip jar 1.13
org.zeroturnaround : zt-exec jar 1.11
org.slf4j : slf4j-simple jar 1.7.30
commons-io : commons-io jar 2.6

Project Modules

There are no modules declared in this project.

wf-exec

Process executor for Java which use Win32 Job Objects on Windows platform. Unlike default process executor this library help you to kill child process when parent dies normally or abnormally (reaps all zombie/defunct process).

AppVeyor License

Supported Java Versions

Oracle & OpenJDK Java 8, 11.

Both the JRE and the JDK are suitable for use with this library.

How it is tested

wf-exec is regularly tested on appveyor (Windows)

Integration with Maven

The project artifacts are available in Maven Central Repository.

To use the official release of wf-exec, please use the following snippet in your pom.xml file.

Add the following to your POM's <dependencies> tag:

<dependency>
    <groupId>io.webfolder</groupId>
    <artifactId>wf-exec</artifactId>
    <version>1.0.4</version>
</dependency>

Download

wf-exec-1.0.4.jar - 163 KB

Example

public class Example {

  private static final boolean WINDOWS  = getProperty("os.name")
                                              .toLowerCase(ENGLISH)
                                              .startsWith("windows");

  public static void main(String[] args) throws IOException {
    // load jni library
    WindowsJniLoader.loadJni();
    
    SubprocessFactory factory = WINDOWS ? WindowsSubprocessFactory.INSTANCE :
                                          JavaSubprocessFactory.INSTANCE;

    SubprocessBuilder builder = new SubprocessBuilder(factory);

    builder.setWorkingDirectory(new File("."));

    builder.setArgv("java.exe", "-version");

    StringBuilder buffer = new StringBuilder();

    Subprocess process = builder.start();
    try (Scanner scanner = new Scanner(process.getErrorStream())) {
      while (scanner.hasNext()) {
        String line = scanner.nextLine().trim();
        if (line.isEmpty()) {
          continue;
        }
        buffer.append(line).append("\r\n");
      }
    }

    // terminate the process
    process.destroy();

    while (process.finished()) {
      // wait until process finished
    }

    // close the native resources
    process.close();

    System.out.println(buffer.toString());
  }
}

License

Licensed under the Apache License.

Note: The included code from bazel is licensed under Apache.

Versions

Version
1.0.0