Package oshi.util
Class ExecutingCommand
java.lang.Object
oshi.util.ExecutingCommand
@ThreadSafe public final class ExecutingCommand extends java.lang.Object
A class for executing on the command line and returning the result of
execution.
-
Method Summary
Modifier and Type Method Description static java.lang.String
getAnswerAt(java.lang.String cmd2launch, int answerIdx)
Return response on selected line index (0-based) after running selected command.static java.lang.String
getFirstAnswer(java.lang.String cmd2launch)
Return first line of response for selected command.static java.util.List<java.lang.String>
runNative(java.lang.String cmdToRun)
Executes a command on the native command line and returns the result.static java.util.List<java.lang.String>
runNative(java.lang.String[] cmdToRunWithArgs)
Executes a command on the native command line and returns the result line by line.
-
Method Details
-
runNative
public static java.util.List<java.lang.String> runNative(java.lang.String cmdToRun)Executes a command on the native command line and returns the result. This is a convenience method to callRuntime.exec(String)
and capture the resulting output in a list of Strings. On Windows, built-in commands not associated with an executable program may requirecmd.exe /c
to be prepended to the command.- Parameters:
cmdToRun
- Command to run- Returns:
- A list of Strings representing the result of the command, or empty string if the command failed
-
runNative
public static java.util.List<java.lang.String> runNative(java.lang.String[] cmdToRunWithArgs)Executes a command on the native command line and returns the result line by line. This is a convenience method to callRuntime.exec(String[])
and capture the resulting output in a list of Strings. On Windows, built-in commands not associated with an executable program may require the stringscmd.exe
and/c
to be prepended to the array.- Parameters:
cmdToRunWithArgs
- Command to run and args, in an array- Returns:
- A list of Strings representing the result of the command, or empty string if the command failed
-
getFirstAnswer
public static java.lang.String getFirstAnswer(java.lang.String cmd2launch)Return first line of response for selected command.- Parameters:
cmd2launch
- String command to be launched- Returns:
- String or empty string if command failed
-
getAnswerAt
public static java.lang.String getAnswerAt(java.lang.String cmd2launch, int answerIdx)Return response on selected line index (0-based) after running selected command.- Parameters:
cmd2launch
- String command to be launchedanswerIdx
- int index of line in response of the command- Returns:
- String whole line in response or empty string if invalid index or running of command fails
-