O'Reilly logo

Exploring Expect by Don Libes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required