public class PowerShell extends Object implements AutoCloseable
Once the session is finished it should be closed in order to free resources.
For doing that, you can either call manually close() or implement a try with resources as
it implements AutoCloseable.
| Modifier and Type | Field and Description |
|---|---|
static String |
END_SCRIPT_STRING |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes all the resources used to maintain the PowerShell context
|
PowerShell |
configuration(Map<String,String> config)
Allows to override jPowerShell configuration using a map of key/value
Default values are taken from file jpowershell.properties, which can be replaced just setting it on project classpath The values that can be overridden are: waitPause: the pause in ms between each loop pooling for a response. |
PowerShellResponse |
executeCommand(String command)
Execute a PowerShell command.
|
PowerShell |
executeCommandAndChain(String command,
com.profesorfalken.jpowershell.PowerShellResponseHandler... response)
Allows to chain command executions providing a more fluent API.
|
PowerShellResponse |
executeScript(BufferedReader srcReader)
Execute the provided PowerShell script in PowerShell console and gets
result.
|
PowerShellResponse |
executeScript(BufferedReader srcReader,
String params)
Execute the provided PowerShell script in PowerShell console and gets
result.
|
PowerShellResponse |
executeScript(String scriptPath)
Executed the provided PowerShell script in PowerShell console and gets
result.
|
PowerShellResponse |
executeScript(String scriptPath,
String params)
Executed the provided PowerShell script in PowerShell console and gets
result.
|
static PowerShellResponse |
executeSingleCommand(String command)
Execute a single command in PowerShell console and gets result
|
boolean |
isLastCommandInError()
Indicates if the last executed command finished in error
|
static PowerShell |
openSession()
Creates a session in PowerShell console an returns an instance which allows
to execute commands in PowerShell context.
|
static PowerShell |
openSession(String customPowerShellExecutablePath)
Creates a session in PowerShell console an returns an instance which allows
to execute commands in PowerShell context.
|
public static final String END_SCRIPT_STRING
public PowerShell configuration(Map<String,String> config)
The values that can be overridden are:
config - map with the configuration in key/value formatpublic static PowerShell openSession() throws PowerShellNotAvailableException
PowerShellNotAvailableException - if PowerShell is not installed in the systempublic static PowerShell openSession(String customPowerShellExecutablePath) throws PowerShellNotAvailableException
customPowerShellExecutablePath - the path of powershell executable. If you are using
the default installation path, call openSession() method insteadPowerShellNotAvailableException - if PowerShell is not installed in the systempublic PowerShellResponse executeCommand(String command)
This method launch a thread which will be executed in the already created PowerShell console context
command - the command to call. Ex: dirpublic static PowerShellResponse executeSingleCommand(String command)
command - the command to executepublic PowerShell executeCommandAndChain(String command, com.profesorfalken.jpowershell.PowerShellResponseHandler... response)
This method allows also to optionally handle the response in a closure
command - the command to executeresponse - optionally, the response can be handled in a closurePowerShell instancepublic boolean isLastCommandInError()
public PowerShellResponse executeScript(String scriptPath)
scriptPath - the full path of the scriptpublic PowerShellResponse executeScript(String scriptPath, String params)
scriptPath - the full path of the scriptparams - the parameters of the scriptpublic PowerShellResponse executeScript(BufferedReader srcReader)
srcReader - the script as BufferedReader (when loading File from jar)public PowerShellResponse executeScript(BufferedReader srcReader, String params)
srcReader - the script as BufferedReader (when loading File from jar)params - the parameters of the scriptpublic void close()
close in interface AutoCloseableCopyright © 2018. All rights reserved.