Package org.appng.tools.os
Class Command
- java.lang.Object
-
- org.appng.tools.os.Command
-
public class Command extends Object
Utility class to conveniently execute command viaRuntime.exec(String)
.- Author:
- Matthias Müller
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Command.StreamConsumer<T>
Interface for a type consuming andInputStream
.
-
Constructor Summary
Constructors Constructor Description Command()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
execute(String command, Command.StreamConsumer<?> outputConsumer, Command.StreamConsumer<?> errorConsumer)
Executes the given command.static int
execute(OperatingSystem os, String command, Command.StreamConsumer<?> outputConsumer, Command.StreamConsumer<?> errorConsumer)
Executes the given command, but only if the givenOperatingSystem
matches.
-
-
-
Field Detail
-
ERROR
public static final int ERROR
- See Also:
- Constant Field Values
-
WRONG_OS
public static final int WRONG_OS
- See Also:
- Constant Field Values
-
-
Method Detail
-
execute
public static int execute(String command, Command.StreamConsumer<?> outputConsumer, Command.StreamConsumer<?> errorConsumer)
Executes the given command.- Parameters:
command
- the command to executeoutputConsumer
- aCommand.StreamConsumer
to consumeProcess.getInputStream()
errorConsumer
- aCommand.StreamConsumer
to consumeProcess.getErrorStream()
- Returns:
- the value returned by
Process.waitFor()
, or -1 if an exception occurred while executing the process.
-
execute
public static int execute(OperatingSystem os, String command, Command.StreamConsumer<?> outputConsumer, Command.StreamConsumer<?> errorConsumer)
Executes the given command, but only if the givenOperatingSystem
matches.- Parameters:
os
- the targetOperatingSystem
command
- the command to executeoutputConsumer
- aCommand.StreamConsumer
to consumeProcess.getInputStream()
errorConsumer
- aCommand.StreamConsumer
to consumeProcess.getErrorStream()
- Returns:
- the return value of
execute(String, StreamConsumer, StreamConsumer)
, if the currentOperatingSystem
matches the desired one, otherwise -2 - See Also:
execute(String, StreamConsumer, StreamConsumer)
-
-