Java library to launch external processes

Overview

ch.vorburger.exec

If you like/use this project, a Star / Watch / Follow me on GitHub is appreciated!

Maven Central Javadocs Build Status Dependabot Status

This project is a small library allowing to launch external processes from Java code in the background, and conveniently correctly pipe their output e.g. into slf4j, await either their termination or specific output, etc.

Release Notes are in CHANGES.md.

Usage

Launching external processes from Java using the raw java.lang.ProcessBuilder API directly can be a little cumbersome. Apache Commons Exec makes it a bit easier, but lacks some convenience. This library makes it truly convenient:

ManagedProcessBuilder pb = new ManagedProcessBuilder("someExec")
    .addArgument("arg1")
    .setWorkingDirectory(new File("/tmp"))
    .getEnvironment().put("ENV_VAR", "...")
    .setDestroyOnShutdown(true)
    .addStdOut(new BufferedOutputStream(new FileOutputStream(outputFile)))
    .setConsoleBufferMaxLines(7000);  // used by startAndWaitForConsoleMessageMaxMs

ManagedProcess p = pb.build();
p.start();
p.isAlive();
p.waitForExit();
// OR: p.waitForExitMaxMsOrDestroy(5000);
// OR: p.startAndWaitForConsoleMessageMaxMs("Successfully started", 3000);
p.exitValue();
// OR: p.destroy();

// This works even while it's running, not just when it exited
String output = p.getConsole();

If you need to, you can also attach a listener to get notified when the external process ends, by using setProcessListener() on the ManagedProcessBuilder with a ManagedProcessListener that implements onProcessComplete() and onProcessFailed().

We currently internally use Apache Commons Exec by building on top, extending and wrapping it, but without exposing this in its API, so that theoretically in the future this implementation detail could be changed.

Advantages

  • automatically logs external process's STDOUT and STDERR using SLF4j out of the box (can be customized)
  • automatically logs and throws for common errors (e.g. executable not found), instead of silently ignoring like j.l.Process
  • automatically destroys external process with JVM shutdown hook (can be disabled)
  • lets you await appearance of certain messages on the console
  • lets you write tests against the expected output

History

Historically, this code was part of MariaDB4j (and this is why it's initial version was 3.0.0), but was it later split into a separate project. This was done to make it usable in separate projects (originally to launch Ansible Networking CLI commands from OpenDaylight, later to manage etcd servers in tests, both from OpenDaylight).

Similarly

For the exec functionality, zt-exec (with zt-process-killer) is similar (but refused to backlink us).

NuProcess is another similar library in the sams space.

For the expect-like functionality, from https://en.wikipedia.org/wiki/Expect#Java, note (in no particular order):

Release

First test that GPG is set up correctly (gpg: no default secret key: No secret key gpg: signing failed: No secret key), and that the settings.xml has the credz for oss.sonatype.org (status: 401 unauthorized):

mvn verify -Pgpg

mvn deploy

Once that works, the next release can be done similarly similarly to https://github.com/vorburger/MariaDB4j#release:

mvn release:prepare
mvn release:perform -Pgpg
mvn release:clean
git push

If mvn release:prepare fails with the following error, then comment out forceSignAnnotated = true under [tag] in ~/.gitconfig:

The git-tag command failed.
[ERROR] Command output:
[ERROR] error: gpg failed to sign the data
[ERROR] error: unable to sign the tag

ToDo

This library is currently used to control daemon style external executables. To launch a process which returns binary (or massive textual) output to its STDOUT (and, presumably, have that piped into a java.io.OutputStream), it would need some tweaks. This would include making the enabled-by-default logging into slf4j, and the built-in startAndWaitForConsoleMessageMaxMs which collects output, a more configurable option.

Contributions & patches more than welcome!

Comments
  • Issue #63 - Provide a callback if the DB process crashes

    Issue #63 - Provide a callback if the DB process crashes

    @duttonw:

    • Split exec from mariaDB4j to new repo
    • Add CONTRIBUTORS.md

    Co-authored-by: Neelesh Shastry [email protected] Co-authored-by: William Dutton[email protected]

    From: https://github.com/vorburger/MariaDB4j/pull/96

    opened by duttonw 6
  • Add flag to ManagedProcess to denote that the process was destroyed before alloted exit time

    Add flag to ManagedProcess to denote that the process was destroyed before alloted exit time

    WatchDog does not set a flag when a process is destroyed (regardless of what it claims), so this PR adds a custom flag to denote whether it was destroyed.

    opened by Anthoknee 4
  • Bump commons-lang3 from 3.8 to 3.8.1

    Bump commons-lang3 from 3.8 to 3.8.1

    Bumps commons-lang3 from 3.8 to 3.8.1.

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Automerge options (never/patch/minor, and dev/runtime dependencies)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)

    Finally, you can contact us by mentioning @dependabot.

    dependencies 
    opened by dependabot-preview[bot] 3
  • Bump slf4j-simple from 1.7.32 to 1.7.33

    Bump slf4j-simple from 1.7.32 to 1.7.33

    Bumps slf4j-simple from 1.7.32 to 1.7.33.

    Commits
    • 2758a97 prepare release 1.7.33
    • a0681b7 fix SLF4J-499
    • c89dc3d Merge branch '1.7-maintenance' of github.com:qos-ch/slf4j into 1.7-maintenance
    • 0d2bd39 add slf4j-reload4j module
    • ae9ee00 start work on 1.7.33-SNAPSHOT
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 2
  • Bump slf4j-api from 1.7.32 to 1.7.33

    Bump slf4j-api from 1.7.32 to 1.7.33

    Bumps slf4j-api from 1.7.32 to 1.7.33.

    Commits
    • 2758a97 prepare release 1.7.33
    • a0681b7 fix SLF4J-499
    • c89dc3d Merge branch '1.7-maintenance' of github.com:qos-ch/slf4j into 1.7-maintenance
    • 0d2bd39 add slf4j-reload4j module
    • ae9ee00 start work on 1.7.33-SNAPSHOT
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 2
  • Bump maven-compiler-plugin from 3.8.0 to 3.8.1

    Bump maven-compiler-plugin from 3.8.0 to 3.8.1

    Bumps maven-compiler-plugin from 3.8.0 to 3.8.1.

    Commits
    • 1b206fe [maven-release-plugin] prepare release maven-compiler-plugin-3.8.1
    • d94a573 Revert "[maven-release-plugin] prepare release maven-compiler-plugin-3.8.1"
    • 0747073 [maven-release-plugin] prepare release maven-compiler-plugin-3.8.1
    • 4f37195 Revert "[maven-release-plugin] prepare release maven-compiler-plugin-3.8.1"
    • 114487b Revert "[maven-release-plugin] prepare for next development iteration"
    • 6fd3a46 [MCOMPILER-379] - Fatal error compiling: basedir ... arget/generated-sources/...
    • a5c6bc5 (doc) Fixed broken links to scm, issue tracker, and mailing list page. (#15)
    • 6c576ab [maven-release-plugin] prepare for next development iteration
    • e09eb57 [maven-release-plugin] prepare release maven-compiler-plugin-3.8.1
    • 3d6b27c [MCOMPILER 366] - Warning about automodules should provide the list of offend...
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Automerge options (never/patch/minor, and dev/runtime dependencies)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)

    Finally, you can contact us by mentioning @dependabot.

    dependencies 
    opened by dependabot-preview[bot] 2
  • Release 3.1.0 ?

    Release 3.1.0 ?

    @duttonw was there anything else you wanted to contribute here before I release, other than #5 ? If not, I'll wip up a short summary of all recent commit in CHANGES.md (or you can?), and push current master as a 3.1.0 to Maven central...

    opened by vorburger 2
  • Bump slf4j-api from 2.0.3 to 2.0.4

    Bump slf4j-api from 2.0.3 to 2.0.4

    Bumps slf4j-api from 2.0.3 to 2.0.4.

    Commits
    • 35dd7ff removed unused META-INF/services entry
    • 440c2f3 prepare release 2.0.4
    • 43a3630 use the class loader that loaded LoggerFactory (instead of the threadContextC...
    • 557bf7c [SLF4J-548] Fix ServiceLoader usage in servlet environment
    • 6324105 enhance manifest with capabilities
    • e540299 edit blurb on release championing
    • dfb41b0 Update README.md
    • 47c7cc7 clarify Logger.makeLoggingEventBuilder javadoc
    • 0be1bc1 Merge branch 'master' of github.com:qos-ch/slf4j
    • d60690c more flexible way to
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 1
  • Bump slf4j-simple from 2.0.3 to 2.0.4

    Bump slf4j-simple from 2.0.3 to 2.0.4

    Bumps slf4j-simple from 2.0.3 to 2.0.4.

    Commits
    • 35dd7ff removed unused META-INF/services entry
    • 440c2f3 prepare release 2.0.4
    • 43a3630 use the class loader that loaded LoggerFactory (instead of the threadContextC...
    • 557bf7c [SLF4J-548] Fix ServiceLoader usage in servlet environment
    • 6324105 enhance manifest with capabilities
    • e540299 edit blurb on release championing
    • dfb41b0 Update README.md
    • 47c7cc7 clarify Logger.makeLoggingEventBuilder javadoc
    • 0be1bc1 Merge branch 'master' of github.com:qos-ch/slf4j
    • d60690c more flexible way to
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 1
  • Bump slf4j-api from 1.7.36 to 2.0.0

    Bump slf4j-api from 1.7.36 to 2.0.0

    Bumps slf4j-api from 1.7.36 to 2.0.0.

    Commits
    • 0614d46 prepare release 2.0.0
    • b1afcd0 javadoc edits
    • 20cd3ad start work on 2.0.0-SNAPSHOT
    • aeebb61 prepare release 2.0.0-beta1
    • 1068cd0 javadoc changes
    • 4e4e56a add CheckReturnValue annotation in org.slf4j.helpers
    • 0dcfa19 check for return value in some oggingEventBuilder methods
    • e7ca8d1 start work on 2.0.0-beta1-SNAPSHOPT
    • 2314de9 add setMessage and log method to the fluent API
    • 508a796 set version to 2.0.0-beta0
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 1
  • Bump slf4j-simple from 1.7.36 to 2.0.0

    Bump slf4j-simple from 1.7.36 to 2.0.0

    Bumps slf4j-simple from 1.7.36 to 2.0.0.

    Commits
    • 0614d46 prepare release 2.0.0
    • b1afcd0 javadoc edits
    • 20cd3ad start work on 2.0.0-SNAPSHOT
    • aeebb61 prepare release 2.0.0-beta1
    • 1068cd0 javadoc changes
    • 4e4e56a add CheckReturnValue annotation in org.slf4j.helpers
    • 0dcfa19 check for return value in some oggingEventBuilder methods
    • e7ca8d1 start work on 2.0.0-beta1-SNAPSHOPT
    • 2314de9 add setMessage and log method to the fluent API
    • 508a796 set version to 2.0.0-beta0
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 1
  • Bump slf4j-api from 2.0.5 to 2.0.6

    Bump slf4j-api from 2.0.5 to 2.0.6

    Bumps slf4j-api from 2.0.5 to 2.0.6.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • Bump slf4j-simple from 2.0.5 to 2.0.6

    Bump slf4j-simple from 2.0.5 to 2.0.6

    Bumps slf4j-simple from 2.0.5 to 2.0.6.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • Unexpected error when calling waitForExit

    Unexpected error when calling waitForExit

    Here's the issue that we're seeing:

    ManagedProcess process = builder.build();
    process.start();
    process.waitForExit(); // Crashes the error below:
    

    waitForExit fails with this:

    Caused by: ch.vorburger.exec.ManagedProcessException: Asked to waitFor Program 
    [/tmp/75968747865555/MysqlDB4j/base/bin/mysql, -uroot, --socket=/tmp/75968747865555/MysqlDB4j.33803.sock] 
    (in working directory /tmp/75968747865555/MysqlDB4j/base), but it was never even start()'ed! |
      |   | at ch.vorburger.exec.ManagedProcess.assertWaitForIsValid(ManagedProcess.java:478)
      |   | at ch.vorburger.exec.ManagedProcess.waitForExitMaxMsWithoutLog(ManagedProcess.java:439) |  
      |   | at ch.vorburger.exec.ManagedProcess.waitForExit(ManagedProcess.java:418) |  
      |   | at com.airbnb.mysql4j.DB.run(DB.java:405) |  
    [...]
    

    This is failing randomly, at a rate of say 5%. Succeeds after retries.

    Based on the comment from here: https://github.com/vorburger/ch.vorburger.exec/blob/07f251115af56a4f6d38eb46cb2cbd76d10a10ed/src/main/java/ch/vorburger/exec/ManagedProcess.java#L198

    ... I suspect (without being able to prove this via a test) that what's happening is this, inside startExecute()

    1. executor.execute starts execution of something that will fail
    2. this.wait(100) returns with no error, but incorrectly fails to detect that the background thread has an error
    3. isAlive = watchDog.isWatching() correctly returns False, because the background thread has indeed failed
    4. waitForExit will call assertWaitForIsValid(), which throws because isAlive = False (from 3) and hasResult = False (from 2)
    opened by mihneagiurgea 0
  • checkResult() should be optional

    checkResult() should be optional

    The waitForExit() methods currently internally (all?) use checkResult().

    This makes it impossible to wait for a non-sucessful exit - which could be handy for some use cases (e.g. a CLI testing tool).

    opened by vorburger 1
  • Parse full existing command line

    Parse full existing command line

    When using this library somewhere where there already is a "command line" (as in an executable + arguments), then the ManagedProcessBuilder as-is currently is more in the way than helpful, as you have to write code to split it:

            var execName = cmdLine.substring(0, cmdLine.indexOf(' ')).strip();
            var procBuilder = new ManagedProcessBuilder(execName);
            var execArgs = cmdLine.substring(execName.length());
            for (String arg : Splitter.on(' ').trimResults().omitEmptyStrings().split(execArgs)) {
                procBuilder.addArgument(arg);
            }
    

    For such uses cases, it would be handy if the ManagedProcessBuilder had a static factory method such as fromCommandLine(String commandLine) which did something like above. It should take quotes appropriately into account, like a shell.

    This would be the ManagedProcessBuilder time equivalent of the already existing ch.vorburger.exec.ManagedProcess.getProcLongName() method (which could be renamed to getCommandLine() at this occassion; and a toString() could be added which uses getCommandLine(), getWorkingDirectory() (as getProcLongName() does) and other state information.

    opened by vorburger 0
Owner
Michael Vorburger ⛑️
Geek Father. EPFL alumni. Speaks Esperanto, Java, no Klingon, but a few other langs. (Works at Google. Formerly at Red Hat. Repos here are personal.)
Michael Vorburger ⛑️
Programming Services and Processes - 04 Secure Programming Techniques

Programación de Servicios y Procesos - 04 Técnicas de Programación Segura Tema 04. Técnicas de Programación segura. Curso 2021/2022. Contenidos Introd

José Luis González Sánchez 5 Dec 27, 2022
A lightweight and extensible library to resolve application properties from various external sources.

Externalized Properties A lightweight and extensible library to resolve application properties from various external sources. Twelve Factor Methodolog

Joel Jeremy Marquez 20 Nov 29, 2022
A lightweight and extensible library to resolve application properties from various external sources.

Externalized Properties A lightweight and extensible library to resolve application properties from various external sources. Twelve Factor Methodolog

Joel Jeremy Marquez 20 Nov 29, 2022
An example on how to build a configurable widget to trigger external searches along with Liferay search to Elasticsearch.

Liferay External Searches An example on how to build a configurable widget to trigger external searches along with Liferay search to Elasticsearch. Ge

Louis-Guillaume Durand 4 Oct 25, 2021
Docker-compose-integration-tstst - An exploration of how to run integration tests against an application that has inconvenient external dependencies (e.g. a SQL database).

Tstst? it was supposed to be docker-compose-integration-tests but i was too lazy to fix it at the outset, and now im trying to convince myself its fun

null 1 Jan 4, 2022
DatasetCreator is a lightweight RESTFul client implementation of the Salesforce CRM Analytics External Data API.

DatasetCreator is a lightweight RESTFul client implementation of the Salesforce CRM Analytics External Data API. It has been deliberately developed with no 3rd party jars with the goal of being a lean, reliable and scalable solution.

Salesforce Platform 6 Dec 16, 2022
Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.

Tinker Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstalling apk. Getting started Add t

Tencent 16.6k Dec 30, 2022
Trust-java - Test Results Verification library for Java

TRUST - Test Results Verification library for Java The TRUST's primary goal is to provide the simple way of different test results verification. Gener

Serhii Shymkiv 2 Nov 19, 2017
Library for converting from one Java class to a dissimilar Java class with similar names based on the Bean convention

Beanmapper Beanmapper is a Java library for mapping dissimilar Java classes with similar names. The use cases for Beanmapper are the following: mappin

null 26 Nov 15, 2022
Create a Music Playlist Library -Core JAVA, JAVA Swing, AWT

Project Specifications Manage Everything about a basic Music Playlist Application in Java A Music Library for Listing, Replaying, Navigating between c

Muhammad Asad 7 Nov 8, 2022
Resconstruct is a java library to infer missing information vectors of java classes.

Reconstruct Resconstruct is a java library to infer missing information vectors of java classes. Features Phantom classes Inheritance solving Dummy fi

Nowilltolife 14 Nov 17, 2022
Z is a Java library providing accessible, consistent function combinators.

Fearless function combination in Java Techniques Unlock your functional programming potential with these combination techniques: Fusion Z.fuse(fn1, fn

J.R. 27 Jun 13, 2022
This is a small library written in Java for minecraft login.

minecraft-auth-library This is a small library written in Java for minecraft login. Usage: Login with microsoft MinecraftAuthenticator minecraftAuthen

Sandro 7 Feb 5, 2022
SpringBoot show case application for reactive-pulsar library (Reactive Streams adapter for Apache Pulsar Java Client)

Reactive Pulsar Client show case application Prerequisites Cloning reactive-pulsar Running this application requires cloning https://github.com/lhotar

Lari Hotari 9 Nov 10, 2022
A bitcoin explorer Java library that utilizes multiple data sources at once.

Bitcoin Explorer A bitcoin explorer library that utilizes multiple data sources at once. Branch Build Unit Tests master development Table of Contents

Scorpius 3 Jan 31, 2022
Nrich is a Java library developed at CROZ whose purpose is to make development of applications on JVM a little easier.

nrich Nrich is a Java library developed at CROZ whose purpose is to make development of applications on JVM a little easier. It contains modules that

CROZ 44 Nov 12, 2022
Portaudio4j - An exploratory project to interact with the PortAudio C library using Java's FFI (Panama) APIs

Examples of PortAudio called by Java's Panama APIs JEP 412. At the moment this is purely exploratory (still kicking the tires) as it progresses in the

Carl Dea 4 Dec 29, 2021
Tzatziki - Decathlon library to ease and promote Test Driven Development of Java microservices!

Tzatziki Steps Library This project is a collection of ready-to-use Cucumber steps making it easy to TDD Java microservices by focusing on an outside-

Decathlon 32 Dec 15, 2022
libraw4j - Java interface to the libraw library

libraw4j (1.0.0-SNAPSHOT) This is heavily W.I.P. Help is welcome! Java interface to the libraw library. Used for reading data from raw images. src/mai

Jacob Andersen 2 Apr 18, 2022