expectj
Class SshSpawn

java.lang.Object
  extended by expectj.AbstractSpawnable
      extended by expectj.SshSpawn
All Implemented Interfaces:
Spawnable

public class SshSpawn
extends AbstractSpawnable
implements Spawnable

A Spawnable for controlling an SSH session using ExpectJ.


Nested Class Summary
 
Nested classes/interfaces inherited from interface expectj.Spawnable
Spawnable.CloseListener
 
Constructor Summary
SshSpawn(com.jcraft.jsch.Channel channel)
          Takes control over an existing SSH channel.
SshSpawn(String remoteHostName, int remotePort, String username, String password)
          Construct a new SSH spawn.
 
Method Summary
 int getExitValue()
          If the Spawn has exited, its exit code is returned.
 InputStream getStderr()
          Get a stream from which the Spawn's stderr can be read.
 OutputStream getStdin()
          Get a stream through which the Spawn's stdin can be written to.
 InputStream getStdout()
          Get a stream from which the Spawn's stdout can be read.
 boolean isClosed()
          Find out whether the Spawn has finished.
 void start()
          This method launches the Spawn.
 void stop()
          Stops a running Spawn.
 
Methods inherited from class expectj.AbstractSpawnable
onClose, setCloseListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface expectj.Spawnable
setCloseListener
 

Constructor Detail

SshSpawn

public SshSpawn(String remoteHostName,
                int remotePort,
                String username,
                String password)
Construct a new SSH spawn.

Parameters:
remoteHostName - The remote host to connect to.
remotePort - The remote port to connect to.
username - The user name with which to authenticate
password - The password with which to authenticate

SshSpawn

public SshSpawn(com.jcraft.jsch.Channel channel)
         throws IOException
Takes control over an existing SSH channel.

Parameters:
channel - The channel we should control. If this channel isn't already connected, Channel.connect() will be called.
Throws:
IOException - If connecting the channel fails.
Method Detail

start

public void start()
           throws IOException
Description copied from interface: Spawnable
This method launches the Spawn. It starts the StreamPipers that enable copying of process stream contents to standard streams.

Specified by:
start in interface Spawnable
Throws:
IOException - on trouble.

getStdout

public InputStream getStdout()
Description copied from interface: Spawnable
Get a stream from which the Spawn's stdout can be read.

Specified by:
getStdout in interface Spawnable
Returns:
A stream that represents stdout of a spawned process.
See Also:
Process.getInputStream()

getStdin

public OutputStream getStdin()
Description copied from interface: Spawnable
Get a stream through which the Spawn's stdin can be written to.

Specified by:
getStdin in interface Spawnable
Returns:
A stream that represents stdin of a spawned process.
See Also:
Process.getOutputStream()

getStderr

public InputStream getStderr()
Description copied from interface: Spawnable
Get a stream from which the Spawn's stderr can be read.

Specified by:
getStderr in interface Spawnable
Returns:
A stream that represents stderr of a spawned process, or null if there is no stderr.
See Also:
Process.getErrorStream()

isClosed

public boolean isClosed()
Description copied from interface: Spawnable
Find out whether the Spawn has finished.

Specified by:
isClosed in interface Spawnable
Returns:
true if a spawned process has finished.

getExitValue

public int getExitValue()
Description copied from interface: Spawnable
If the Spawn has exited, its exit code is returned.

Specified by:
getExitValue in interface Spawnable
Returns:
The exit code of the finished spawn.
See Also:
Spawnable.isClosed(), System.exit(int)

stop

public void stop()
Description copied from interface: Spawnable
Stops a running Spawn. After this method returns, Spawnable.isClosed() must return true.

Specified by:
stop in interface Spawnable


Copyright © 2010. All Rights Reserved.