Once a session is established, you can interact with it using the client.sessions module.
Basic Shell Interaction
Use client.sessions.session(session_id) to get a session object. You can then use .write() and .read().
shell = client.sessions.session('1')
shell.write('whoami')
print(shell.read())
Running commands with output and termination strings
Because determining when a session command is finished is non-trivial, use run_with_output(command, terminating_strs). This method waits until one of the strings in terminating_strs appears in the output.
session_id = '1'
# Wait for '----' to appear in the ARP table output
client.sessions.session(session_id).run_with_output('arp', ['----'])
Using timeouts
You can specify a timeout (in seconds). If timeout_exception is set to False, the method will return whatever data was captured before the timeout expired instead of raising an error.
# Wait up to 10 seconds for '----'
client.sessions.session('1').run_with_output('arp', ['----'], timeout=10, timeout_exception=False)
# Basic read/write
session = client.sessions.session('1')
session.write('whoami')
print(session.read())
# Run command and wait for specific output pattern
session.run_with_output('arp', ['----'])
# Run command with a 10s timeout (no exception on timeout)
session.run_with_output('arp', ['----'], timeout=10, timeout_exception=False)