Functions And Variables In The Expect Extension

Writing C and C++ code that uses the Expect extension is similar to writing C code that uses Tcl. For example, you can call Tcl_Eval to execute any Expect or Tcl command. The following statements spawn a telnet process and print the new spawn id. Notice the explicit declaration of telnet_cmd as an array instead of a pointer to a string constant. The array declaration guarantees that the characters are put into writeable memory—a requirement of Tcl_Eval.

char *spawn_id;
char telnet_cmd[] = "spawn telnet";

Tcl_Eval(interp,telnet_cmd);
spawn_id = Tcl_GetVar(interp,"spawn_id",0);
printf("spawn id is %s\n",spawn_id);

It is possible to call Expect’s commands directly. However, this is a little harder and there is generally no good reason to do so, so it is not documented here.

A number of functions and variables are explicitly made public with C and C++ interfaces. Including the file expect_tcl.h gains access to these public symbols. They are defined in this section. Most of them are useful for writing your own main customized from Expect or tclsh. The descriptions are brief since most of the functional aspects are described in Chapter 9 (p. 209).

The first group of variables are shared by the Tcl-less Expect library, the Expect extension, and the Expect program. In this chapter, only their use in the Expect extension and program will be described.

Shared Variables

int exp_disconnected;

exp_disconnected is initially set to 0. It is set to 1 if ...

Get Exploring Expect now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.