public class PowerShell extends Object implements Closeable
open() or
open(java.lang.String). Instances should always be closed with
close() to free resources.| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this PowerShell session and frees all resources associated with
it.
|
static String |
escapePowerShellString(String s)
Wraps a string in quotes and escapes all PowerShell special characters.
|
String |
executeCommands(String... commands)
Executes one or more PowerShell commands.
|
static PowerShell |
open()
Opens a new PowerShell session with default executable.
|
static PowerShell |
open(String customExecutable)
Opens a new PowerShell session with the provided executable.
|
public static PowerShell open() throws IOException
IOException - if an IOException occurred on process creation.public static PowerShell open(String customExecutable) throws IOException
customExecutable - the PowerShell executable. Can be an executable
name like "pwsh" or a path to the executable file.IOException - if an IOException occurred on process creation.public void close()
close in interface Closeableclose in interface AutoCloseablepublic String executeCommands(String... commands) throws PowerShellExecutionException, IOException
executeCommands(
"if ($cond) {",
" Do-Stuff",
"}")
Internally, the commands are just joined with a semicolon ';'.commands - one or more commands to execute.PowerShellExecutionException - if a command encountered an error
(wrote something to the standard error stream) while executing.IOException - if an IOException occurred while reading the output
of the commands.IllegalStateException - if this PowerShell session was already
closed, or the process or its output stream has terminated too early.RuntimeException - if the current thread was interrupted while
executing.public static String escapePowerShellString(String s)
s - the string to be escaped.Copyright © 2019. All rights reserved.