Package com.jgcomptech.tools
Class CommandInfo
- java.lang.Object
-
- com.jgcomptech.tools.CommandInfo
-
public final class CommandInfo extends java.lang.Object
Allows you to run console commands and either run them elevated or not and return the result to a string.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CommandInfo.Output
Output object that is returned after the command has completed.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CommandInfo.Output
Run(java.lang.String command, java.lang.String args)
Runs command and returns results to ArrayList in Output object.static CommandInfo.Output
Run(java.lang.String command, java.lang.String args, boolean elevate)
Runs command elevated, shows cmd window and pauses window when command is complete.static CommandInfo.Output
Run(java.lang.String command, java.lang.String args, boolean elevate, boolean hideWindow, boolean keepWindowOpen)
Runs command according to parameters, will only open cmd window if OS is Windows.
-
-
-
Method Detail
-
Run
public static CommandInfo.Output Run(java.lang.String command, java.lang.String args) throws java.io.IOException, java.lang.InterruptedException
Runs command and returns results to ArrayList in Output object.- Parameters:
command
- Command to runargs
- Arguments to pass to command- Returns:
- Output object
- Throws:
java.io.IOException
- if error occursjava.lang.InterruptedException
- if command is interrupted
-
Run
public static CommandInfo.Output Run(java.lang.String command, java.lang.String args, boolean elevate) throws java.io.IOException, java.lang.InterruptedException
Runs command elevated, shows cmd window and pauses window when command is complete.If "elevate" parameter is false, it is ignored and and results will be saved to Output object
If OS is not Windows, "elevate" parameter is ignored and results will be saved to Output object
- Parameters:
command
- Command to runargs
- Arguments to pass to commandelevate
- Boolean to set if command should be run elevated, if true Output object will be empty- Returns:
- Output object
- Throws:
java.io.IOException
- if error occursjava.lang.InterruptedException
- if command is interrupted
-
Run
public static CommandInfo.Output Run(java.lang.String command, java.lang.String args, boolean elevate, boolean hideWindow, boolean keepWindowOpen) throws java.io.IOException, java.lang.InterruptedException
Runs command according to parameters, will only open cmd window if OS is Windows.If OS is not Windows, all boolean parameters are ignored and results will be saved to Output object
- Parameters:
command
- Command to runargs
- Arguments to pass to commandelevate
- Boolean to set if command should be run elevated, if true Output object will be emptyhideWindow
- If true, cmd window will be hidden, if true, and elevate is false, results will be saved to Output objectkeepWindowOpen
- If true, pauses cmd window and forces it to stay open after command is completedIf false and "elevate" is true, cmd window will close after command is completed
This parameter is ignored if "hideWindow" is true, this prevents cmd window from staying open when hidden and unnecessarily using RAM
- Returns:
- Output object
- Throws:
java.io.IOException
- if error occursjava.lang.InterruptedException
- if command is interrupted
-
-