Package oshi.util
Class ExecutingCommand
java.lang.Object
oshi.util.ExecutingCommand
A class for executing on the command line and returning the result of execution.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
getAnswerAt
(String cmd2launch, int answerIdx) Return response on selected line index (0-based) after running selected command.static String
getFirstAnswer
(String cmd2launch) Return first line of response for selected command.Executes a command on the native command line and returns the result.Executes a command on the native command line and returns the result line by line.Executes a command on the native command line and returns the result line by line.
-
Method Details
-
runNative
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
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
-
runNative
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 arrayenvp
- array of strings, each element of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process.- Returns:
- A list of Strings representing the result of the command, or empty string if the command failed
-
getFirstAnswer
Return first line of response for selected command.- Parameters:
cmd2launch
- String command to be launched- Returns:
- String or empty string if command failed
-
getAnswerAt
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
-