Code polish, added Shell convenience method
This commit is contained in:
parent
3ab5076d9b
commit
740087f2cf
@ -27,12 +27,29 @@ class ShellAsyncExecutor extends ShellExecutor {
|
|||||||
*/
|
*/
|
||||||
public static
|
public static
|
||||||
boolean run(String executableName, String... args) {
|
boolean run(String executableName, String... args) {
|
||||||
ShellExecutor shell = new ShellExecutor();
|
ShellAsyncExecutor shell = new ShellAsyncExecutor();
|
||||||
shell.setExecutable(executableName);
|
shell.setExecutable(executableName);
|
||||||
shell.addArguments(args);
|
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
|
@Override
|
||||||
|
@ -87,6 +87,25 @@ class ShellExecutor {
|
|||||||
return shell.start() == 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) {
|
||||||
|
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.
|
* 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
|
public final
|
||||||
ShellExecutor addArguments(final String... paths) {
|
ShellExecutor addArguments(final String... args) {
|
||||||
for (String path : paths) {
|
for (String path : args) {
|
||||||
this.arguments.add(path);
|
this.arguments.add(path);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
Loading…
Reference in New Issue
Block a user