Skip to content

Standardize Handling Process output#2979

Merged
jeremylong merged 7 commits intomainfrom
standardizeProcessOutput
Dec 1, 2020
Merged

Standardize Handling Process output#2979
jeremylong merged 7 commits intomainfrom
standardizeProcessOutput

Conversation

@jeremylong
Copy link
Copy Markdown
Collaborator

Dependency-check may execute a handful of executables. The handling of the process may have worked in most cases - but the handling was inconsistent and in some cases wrong (checking for an exit code before attempting to read from the streams, etc.). The PR introduces a standardized way of handling the output of a Process by introducing Processor' and ProcessReader. Threads are used to consume the output of the Process`.

Usage examples:

            final Process process = processBuilder.start();
            try (ProcessReader processReader = new ProcessReader(process)) {

                processReader.readAll();

                String standardOutput = processReader.getOutput();
                String errorOutput = processReader.getError();
                int exitValue = process.exitValue();
            }
            final Process process = processBuilder.start();
            try (CustomProcessor processor = new CustomProcessor();
                    ProcessReader processReader = new ProcessReader(process, processor)) {

                processReader.readAll();

                String errorOutput = processReader.getError();
                int exitValue = process.exitValue();
            }

@boring-cyborg boring-cyborg Bot added core changes to core utils changes to utils labels Nov 26, 2020
@jeremylong jeremylong merged commit 120587d into main Dec 1, 2020
@jeremylong jeremylong deleted the standardizeProcessOutput branch January 2, 2021 13:04
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jan 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

core changes to core utils changes to utils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant