From 740087f2cfe4f1332d7b362789d1bee839aea5ff Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 18 Jul 2017 02:25:10 +0200 Subject: [PATCH] Code polish, added Shell convenience method --- .../util/process/ShellAsyncExecutor.java | 23 ++++++++++++++++--- src/dorkbox/util/process/ShellExecutor.java | 23 +++++++++++++++++-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/dorkbox/util/process/ShellAsyncExecutor.java b/src/dorkbox/util/process/ShellAsyncExecutor.java index 0f43e18..76cfcee 100644 --- a/src/dorkbox/util/process/ShellAsyncExecutor.java +++ b/src/dorkbox/util/process/ShellAsyncExecutor.java @@ -27,12 +27,29 @@ class ShellAsyncExecutor extends ShellExecutor { */ public static boolean run(String executableName, String... args) { - ShellExecutor shell = new ShellExecutor(); + ShellAsyncExecutor shell = new ShellAsyncExecutor(); shell.setExecutable(executableName); shell.addArguments(args); - shell.createReadWriterThreads(); - return shell.start(false) == 0; + return shell.start() == 0; + } + + /** + * This is a convenience method to easily create a default process. Will immediately return, and does not wait for the process to finish + * + * @param executableName the name of the executable to run + * @param args the arguments for the executable + * + * @return true if the process ran successfully (exit value was 0), otherwise false + */ + public static + boolean runShell(String executableName, String... args) { + ShellAsyncExecutor shell = new ShellAsyncExecutor(); + shell.setExecutable(executableName); + shell.addArguments(args); + shell.executeAsShellCommand(); + + return shell.start() == 0; } @Override diff --git a/src/dorkbox/util/process/ShellExecutor.java b/src/dorkbox/util/process/ShellExecutor.java index fe3d58a..202660e 100644 --- a/src/dorkbox/util/process/ShellExecutor.java +++ b/src/dorkbox/util/process/ShellExecutor.java @@ -87,6 +87,25 @@ class ShellExecutor { return shell.start() == 0; } + /** + * This is a convenience method to easily create a default process. Will immediately return, and does not wait for the process to finish + * + * @param executableName the name of the executable to run + * @param args the arguments for the executable + * + * @return true if the process ran successfully (exit value was 0), otherwise false + */ + public static + boolean runShell(String executableName, String... args) { + ShellExecutor shell = new ShellExecutor(); + shell.setExecutable(executableName); + shell.addArguments(args); + shell.executeAsShellCommand(); + + // blocks until finished + return shell.start() == 0; + } + /** * This will cause the spawned process to pipe it's output to a String, so it can be retrieved. */ @@ -164,8 +183,8 @@ class ShellExecutor { } public final - ShellExecutor addArguments(final String... paths) { - for (String path : paths) { + ShellExecutor addArguments(final String... args) { + for (String path : args) { this.arguments.add(path); } return this;