|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.maverick.ssh.Shell
This class provides an enhanced user shell that enables the user to trap the
output of single commands in a ShellProcess
.
The basic process of setting up a shell is as follows:
// Create SshClient instance and authenticate .. // Create a Shell instance Shell shell = new Shell(ssh); shell.createSession();
If the createSession method fails to determine the remote operating system an exception will be thrown. You can manually set the required fields using the setter methods of this class before calling createSession. This is an example of the settings required to configure a Windows shell.
Shell shell = new Shell(ssh2); // First turn off failing on unknown os type, by default the Shell will now // throw an exception if the operating system is unknown. shell.setFailOnUknownOS(false); // Now set the command that sets the prompt on Windows shell.setPromptCommand("PROMPT=foo#"); // Tell the Shell what the actual prompt will be shell.setPrompt("foo#"); // Finally make sure that Windows EOL is used shell.setEOL("\r\n"); // This now executes without hanging. shell.createSession();
Constructor Summary | |
Shell(SshClient ssh)
|
Method Summary | |
void |
createSession()
Construct a new scripted session ready for command execution. |
void |
createSession(java.lang.String term,
int cols,
int rows)
Construct a new scripted session ready for command execution. |
ShellProcess |
execute(java.lang.String cmd)
Execute a command within the shell. |
void |
exit()
Exit the session. |
ShellEnvironment |
getEnvironment()
Get the remote shell's environment. |
boolean |
isClosed()
|
static void |
setDefaultEOL(java.lang.String defaultEOL)
Set the deafult EOL string for unknown operating systems. |
void |
setEOL(java.lang.String eol)
Tell the Shell what EOL to use when sending user input to the server. |
void |
setExitCommand(java.lang.String exitCommand)
Tell the Shell what the exit command of the shell is. |
void |
setFailOnUknownOS(boolean failOnUnknownOS)
If the ShellEnvironment class cannot determin the remote shell it defaults to a UNIX type shell. |
void |
setPrompt(java.lang.String actualPrompt)
Tell the Shell what the remote prompt will be. |
void |
setPromptCommand(java.lang.String promptCommand)
Tell the Shell what the command is to set the prompt on the remote shell. |
void |
setPromptTimeoutPeriod(int waitForPromptTimeoutPeriod)
Set the wait for prompt timeout period. |
void |
setShellInitTimePeriod(int shellInitTimePeriod)
Set the shell initialization time period. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Shell(SshClient ssh)
Method Detail |
public void setEOL(java.lang.String eol)
eol
- Stringpublic void setPrompt(java.lang.String actualPrompt)
Shell shell = new Shell(ssh2); // First turn off failing on unknown os type, by default the Shell will now // throw an exception if the operating system is unknown. shell.setFailOnUknownOS(false); // Now set the command that sets the prompt on Windows shell.setPromptCommand("PROMPT=foo#"); // Tell the Shell what the actual prompt will be shell.setPrompt("foo#"); // Finally make sure that Windows EOL is used shell.setEOL("\r\n"); // This now executes without hanging. shell.createSession();
actualPrompt
- Stringpublic void setExitCommand(java.lang.String exitCommand)
exitCommand
- Stringpublic void setShellInitTimePeriod(int shellInitTimePeriod)
shellInitTimePeriod
- int milliseconds to wait before sending any commandspublic void setPromptTimeoutPeriod(int waitForPromptTimeoutPeriod)
waitForPromptTimeoutPeriod
- intpublic void setFailOnUknownOS(boolean failOnUnknownOS)
failOnUnknownOS
- booleanpublic void setPromptCommand(java.lang.String promptCommand)
promptCommand
- Stringpublic void createSession() throws SshException, ChannelOpenException, ShellTimeoutException
SshException
ChannelOpenException
ShellTimeoutException
public void createSession(java.lang.String term, int cols, int rows) throws SshException, ChannelOpenException, ShellTimeoutException
term
- Stringcols
- introws
- int
SshException
ChannelOpenException
ShellTimeoutException
public boolean isClosed()
public ShellProcess execute(java.lang.String cmd) throws java.io.IOException, ShellTimeoutException
ShellProcess
object.
cmd
- String
java.io.IOException
ShellTimeoutException
public void exit() throws ShellTimeoutException, java.io.IOException
Exit the session.
This method executes the "exit" command and waits for the session to close before returning.
java.io.IOException
ShellTimeoutException
public ShellEnvironment getEnvironment()
public static void setDefaultEOL(java.lang.String defaultEOL)
defaultEOL
- String
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |