Before discussing the specific details of how a command pipeline is used to enable the GUI and the simulator to communicate with one another, a brief overview of pipes and a small example of their operation is presented.
Consider, for example, a situation in which a Tcl script
wishes to send two numbers to a subprocess which will add these two
numbers and then send back the sum. Such a
Tcl script is presented in Figure 5.2. Because
the first character of the first argument to the open command
is a vertical bar, commonly referred to a pipe symbol, the
open command will actually execute the program given by the
text following the pipe character (addnum) as a subprocess.
A command pipeline is opened to that process; the standard input and
standard output of the subprocess are tied to the file identifier,
fid, returned by the open command. Whenever the
subprocess reads from standard input it is actually reading information
put into the pipe by the Tcl script via the file identifier.
Likewise, any information that the subprocess attempts to display on
standard output will be intercepted by the Tcl script through
the file identifier.
Figure 5.2: Tcl Script Opening a Pipe to an Executable.
The subprocess, addnum, invoked by the above Tcl script can be written in any language, either interpreted or compiled. The only assumption made by the Tcl script of the subprocess is that it take two numbers from standard input and produce the sum of these two numbers on standard output. Such a program, written in C++, is presented in Figure 5.3. Assuming that the compiled addnum binary is in the same directory as the Tcl script, the end user need only run the Tcl script; the addnum binary will be executed transparently to the user.
Figure 5.3: The C++ Program addnum.