Expecting From Streams
Both exp_expectl and exp_expectv have analogous functions that work on streams instead of file descriptors. The stream functions have the same names as their file counterparts except that the stream functions have an "f" in the name. This is similar to the distinction between write and fwrite. Both of the stream versions are identical to their file counterparts except that the first argument is a stream instead of a file descriptor.
exp_fexpectl is the stream version of exp_expectl. A simple example looks like this:
FILE *fp = exp_popen("telnet");
exp_fexpectl(fp, exp_glob, "prompt*", 1, exp_end);
On some systems, the stream versions of the expect functions are much slower than the file descriptor versions because there is no way to portably read an unknown number of bytes without the potential of timing out. Thus, characters are read one at a time. While automated versions of interactive programs do not usually demand high speed, the file descriptor functions are likely to be more efficient on all systems.
You can get the best of both worlds, writing with the usual stream functions (i.e., fprintf) and reading with the file descriptor versions of expect, as long as you do not attempt to intermix other stream input functions (e.g., fgetc). To do this, pass "fileno(stream)" as the file descriptor to exp_expectl or exp_expectv. Fortunately, there is little reason to use anything but the expect functions when reading from interactive programs.