From: Maraglia, D. <dom...@in...> - 2003-02-28 17:14:09
|
Hello, I am having difficutlies while using the expect module to "capture" the output of a program called from within my perl script. Briefly, all I would like to do is: 1) call an interactive (shell) program from within my perl script 2) pass the program keystrokes 3) capture the text of certain responses from the shell program, preferablly in an array, as the shell program will return several lines of output which need to be analyzed. 1 and 2 are not problem at all, but I can not figure out number 3. Here is an example of what I am doing: ($cfg = Expect->spawn("cfg")) || die "Couldn't spawn relcfg, $!"; unless ($cfg->expect(10,"Enter selection: ")) { die "Execution of relcfg failed, ".$rel_cfg>exp_error()."\n"; } print $cfg "2\r"; unless ($cfg->expect(10,"Enter selection: ")) { die "Execution of relcfg failed, ".$cfg>exp_error()."\n"; } print $cfg "1\r"; unless ($cfg->expect(10,"Enter selection: ")) { die "Execution of relcfg failed, ".$cfg>exp_error()."\n"; } print $cfg "1\r"; unless ($cfg->expect(10,"Use CHAP for discovery [y/N/q]? ")) { die "Execution of relcfg failed, ".$cfg>exp_error()."\n"; } $cfg->send("N\r"); After sending the "N\r" the shell program will search and return information to the terminal and then prompt the user to quit the program; I can easily send commands to exit the program, but how do I capture the information returned by the program? I have tried the following constructs, and various permuatation, to no avail. $cfg->expect(0); $targets = $cfg->before(); @targets = $rel_cfg->before(); Thanks, Dominic |