Package com.sshtools.client.shell
Class ExpectShell.ExpectShellBuilder
java.lang.Object
com.sshtools.client.shell.ExpectShell.ExpectShellBuilder
- Enclosing class:
- ExpectShell
Builder that creates an
ExpectShell.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build the shell.create()Create a new builder.withDetectSettings(boolean detectSettings) Set whether the operating system and it's settings should be detected by examining the stream.withEncoding(String encoding) Set the character encoding to use for transferring string content.withEncoding(Charset encoding) Set the character encoding to use for transferring string content.withInput(InputStream input) Select theInputStreamto read input from.withOS(int os) Deprecated, for removal: This API element is subject to removal in a future version.withOS(ExpectShell.OS os) Specify the operating system for this shell.Prevent operating system and it's settings being detected by examining the stream.withOutput(OutputStream output) Select theOutputStreamto write output to.withPasswordErrorText(String passwordErrorText) Set the pattern to look for to indicate failure of a password when prompted.withPasswordPrompt(String passwordPrompt) Set the pattern to look for for elevated commands usingExpectShell.su(String)and friends that require a password.withSession(SessionChannelNG session) Specify the session to use, from which theInputStreamandOutputStreamcan be derived.withSession(AbstractSessionTask<SessionChannelNG> session) Specify the remote server identification, which may be used as part of operating system detection.withStartupTimeout(Duration startupTimeout) How long to wait for the shells first prompt before giving up and failing.withStartupTimeoutSec(int startupTimeout) How long to wait in seconds for the shells first prompt before giving up and failing.Specify the task from which to derive the session to use, from which theInputStreamandOutputStreamcan be derived.withTrigger(ShellStartupTrigger trigger) Set a callback that is invoked to query if a command line would allow a shell to start.
-
Constructor Details
-
ExpectShellBuilder
public ExpectShellBuilder()
-
-
Method Details
-
create
Create a new builder.- Returns:
- builder
-
withoutDetectSettings
Prevent operating system and it's settings being detected by examining the stream.- Returns:
- builder for chaining
-
withDetectSettings
Set whether the operating system and it's settings should be detected by examining the stream.- Parameters:
detectSettings- detect settings- Returns:
- builder for chaining
-
withTrigger
Set a callback that is invoked to query if a command line would allow a shell to start.- Parameters:
trigger- shell startup trigger- Returns:
- builder for chaining
-
withPasswordErrorText
Set the pattern to look for to indicate failure of a password when prompted. Defaults toExpectShell.PASSWORD_ERROR_TEXT. This may be a regular expression.- Parameters:
passwordErrorText- password error text- Returns:
- builder for chaining
-
withPasswordPrompt
Set the pattern to look for for elevated commands usingExpectShell.su(String)and friends that require a password. Defaults toExpectShell.DEFAULT_PASSWORD_PROMPT. This may be a regular expression.- Parameters:
password- prompt- Returns:
- builder for chaining
-
withEncoding
Set the character encoding to use for transferring string content.- Parameters:
encoding- encoding- Returns:
- builder for chaining
-
withEncoding
Set the character encoding to use for transferring string content.- Parameters:
encoding- encoding- Returns:
- builder for chaining
-
withInput
Select theInputStreamto read input from. You would either manually set theInputStreamandOutputStream, or alternatively provide aSessionChannelNGfrom which to derive the streams. -
withOutput
Select theOutputStreamto write output to. You would either manually set theInputStreamandOutputStream, or alternatively provide aSessionChannelNGfrom which to derive the streams. -
withSession
Specify the session to use, from which theInputStreamandOutputStreamcan be derived. You may alternatively specify the streams yourself.Providing the session will also allow the remote server identification to be automatically queries.
- Parameters:
session- session- Returns:
- this for chaining
-
withTask
Specify the task from which to derive the session to use, from which theInputStreamandOutputStreamcan be derived. You may alternatively specify the streams yourself.- Parameters:
task- task- Returns:
- this for chaining
-
withSession
Specify the remote server identification, which may be used as part of operating system detection. When not provided, and either aSessionChannelNGor aAbstractSessionTaskhas been provided, the remote identification can be obtain automatically.- Parameters:
remoteIdentification- remote identification- Returns:
- this for chaining
-
withOS
Specify the operating system for this shell. This will determine various parameters such as the commands to run, exit code variables, newline sequences and more.When not specified, the default will be determined by examining the output and environment.
- Parameters:
os- operating system- Returns:
- this for chaining
-
withOS
Deprecated, for removal: This API element is subject to removal in a future version.Specify the operating system for this shell. This will determine various parameters such as the commands to run, exit code variables, newline sequences and more.When not specified, the default will be determined by examining the output and environment.
- Parameters:
os- operating system legacy code- Returns:
- this for chaining
-
withStartupTimeout
How long to wait for the shells first prompt before giving up and failing.- Parameters:
startupTimeout- startup timeout- Returns:
- this for chaining
-
withStartupTimeoutSec
How long to wait in seconds for the shells first prompt before giving up and failing.- Parameters:
startupTimeout- startup timeout in seconds- Returns:
- this for chaining
-
build
Build the shell.- Returns:
- shell
- Throws:
SshException- on SSH errorIOException- on IO errorShellTimeoutException- on timeout
-