Previous Topic: RemoteTarget.receivedResult MethodNext Topic: RemoteTarget.wasAborted Method


RemoteTarget.result Method

Scripts produce two types of result information. The output typically written to the screen and a final return value. This method retrieves a representation of the return value of a remote execution process. Because returning a result is the last step in script evaluation, this method only returns a valid value if script execution successfully completes. hasCompleted() returns true and errorOccurred() returns false. Because the return value of a remote execution must be transferred over the network to the system that originated the request, it is serialized into an XML representation on the remote system and the RemoteTarget.result() method returns the result value in its serialized representation.

Turn the serialized representation into a regular JavaScript value using the get-remoteResult() funclet with the RemoteTarget object itself as a parameter. Typically there is no need for scripts to call result() directly. Serialization maintains type information. for example, if the remote node returns a number, get-remoteResult() returns a value of type number. If the remote system returns a Date object, it also becomes a date on the originating system.

Return values from remote scripts are not limited to simple data types. Complex arrays or data-only objects can also be returned, allowing remote execution to transfer large amounts of date between servers. The only limitation is that the data structures must not contain any circular references.

This method has the following syntax:

result()

The remote script returns a string with a serialized XML representation of the value.

Example

Get serialized representation and actual value of a remote execution:

rt = new RemoteTarget("ascli1", "bob", "ca123456");
run-remote "[1,2,3]" on rt -wait
? rt.result()
v = get-remoteResult(rt) // Calls result() internally
? typeof v      // Array
? typeof v[0]   // number
arrdump v

See also:

RemoteTarget.output Method

get-remoteResult Command--Get Result from a Remote Target (Funclet)