Persistent consoles allow you to maintain a persistent fshell (or other console application) instance on a device while actual console connections come and go. A persistent console consists of a persistent side, which is owned by a fshell or other application as its console, and a transient side, which can be connected to or disconnected from another console at any time. This allows you to interact with the persistent console owning application using any console connection available on the device at the time.
To illustrate, we can create a new persistent console thus:
c:\>pcons new "my pcons"
This create a new, disconnected persistent console. We can use the pcons command see it:
c:\>pcons list Name Creator Reader Writer my pcons fshell::pcons_00 - -
Note that no reader or writer are attached. We can now connect to the console:
c:\>pcons connect "my pcons" pcons: connecting to existing console my pcons. c:\>pcons list Name Creator Reader Writer my pcons(*) fshell::pcons_00 vt100tcpcons_fshell vt100tcpcons_fshell (*) indicates current console
Now, pcons list
shows what transient console the persistent console is connected to - vt100tcpcons_fshell
. It also indicates with a (*)
the persistent console that we are currently interacting with.
If the TCP console we are currently using is disconnected for any reason (perhaps we lost the connection with the device), then the transient side of the console will simply be disconnected and the persistent side will be unaffected. If it tries to interact with the console (perhaps to write some data to it), the call will simply block until we get a new transient side. Hence, after the transient console connection is lost, we can simply reconnect to the same fshell
when we are able to re-establish a connection with the device and continue from where we left off, with no state lost.
Note, if we exit the fshell
session that is connected to the persistent side of the console, the persistent console will be destroyed:
c:\>exit pcons: disconnected from my pcons c:\>pcons list c:\>
Hence you should be careful not to exit the fshell
session attached to the persistent side of the console if you are relying on the persistency of it to maintain state.
We can disconnect the transient side of a persistent console using pcons disconnect
:
c:\>pcons disconnect pcons: disconnected from my pcons c:\>pcons Name Creator Reader Writer my pcons fshell::pcons_00 - - c:\>
We can also disconnect a persistent console that we are not currently interacting with by specifying it's name to pcons disconnect
.
The above shows the basics of creating a persistent console, however there are several ways of doing this.
All fshell commands support an option --persistent-console
, similar to --console
but creating a persistent console. For example,
c:\>fshell --persistent-console "fshell_pcons"
Note, this call does not return; the new fshell
instance is waiting for input on the persistent console, which is currently disconnected. Instead, it may be more useful to use the start command to create the new fshell session:
c:\>start fshell --persistent-console "fshell_pcons" c:\>
This creates a new process in the background, which owns a a new persistent console.
c:\>pcons list Name Creator Reader Writer my pcons fshell::pcons_00 - - fshell_pcons fshell(2) - -
This equivalent to typing pcons new fshell_pcons
.
You can also specify a process to launch when using pcons new
by specifying a command and arguments after the console name. For example,
c:\>pcons new ptf_pcons ptf c:\>pcons connect ptf_pcons pcons: connecting to existing console ptf_pcons. PromptTestFramework 007d !>
Instead of pcons new
, you could have instead used
c:\>start ptf --persistent-console ptf_pcons
The pcons command also supports a start
argument, which is similar to new
, but with the following semantics:
If a persistent console with the given name already exists, it will not be created
a connection with the named persistent console will be established.
This can provide a useful shortcut to start interacting with the process attached to the persistent side of the console, creating it if it doesn't already exist. Note, you can specify a command and arguments to start
as with new
, but these will be ignored if the persistent console already exists.
c:\>pcons start "my pcons" pcons: connecting to existing console my pcons. c:\> c:\>pcons start "new pcons" pcons: connecting to new console new pcons. c:\>
You can use pcons connect
to connect a new console as the transient side by using the --console
option:
c:\>pcons connect "my pcons" --console vt100tcpcons
This will create a new console implementation of the type specified and connect it to the persistent console.
As stated earlier, when a persistent consoles transient side is disconnected, any operations on it will block. This will generally cause the process connected to the persistent side to lock up until a real console implementation is connected. If you want to allow this process to run, without blocking while no transient console is connected, you can connect it to the null console:
c:\>pcons connect "my pcons" --console nullcons
This cause all output written by the persistent process to be discarded, and hence allow the process to run while no console is connected to the device.
Copyright (c) 2009-2010 Accenture. All rights reserved.