By default, a new Autoshell session is created for each command run on a RemoteTarget object. When running multiple commands on the same target, it is preferable to use a single persistent session to execute multiple scripts. Additionally a persistent session maintains state. For example, a variable created during one execution is still available during subsequent evaluations.
Calling createRemoteContext() on a RemoteTarget object creates a new Autoshell session on the remote system, and keeps it open until either destroyRemoteContext() is called, or the RemoteTarget object is collected. Calling createRemoteContext() when a context exists destroys the existing context and creates a new one.
This method has the following syntax:
createRemoteContext()
The method returns one of the following error codes:
Indicates success.
Indicates a connection error, for example, host unknown.
Indicates an authentication error.
Example
Create a persistent session, define a variable in the first evaluation and retrieve it in the second one:
rt=new RemoteTarget("ascli1");
if(rt.createRemoteContext()==RemoteTarget.REM_ERR_NONE)
{
run-remote x=42 on rt
run-remote x on rt -wait
? get-remoteResult(rt) // 42
rt.destroyRemoteContext();
? get-remoteResult(rt) // empty
}
else
{
? "Error occurred!";
}
|
Copyright © 2013 CA.
All rights reserved.
|
|