I feel stupid for asking this, but I've tried a couple things and I'm not sure where to go with it.
From the Expect.pm documentation:
$object->log_file("filename" | $filehandle | \&coderef | undef)
Log session to a file. All characters send to or received from the spawned process are written to the file.
I'd like to pass the $filehandle to log_file. However, when I tried this:
open (LOG, ">>" .$opt{l});
my $sess = Expect->spawn("telnet $ip");
$sess->log_file(LOG)
I get a file named 'LOG' in the directory that I'm running the script out of. After some investigation, I tried this:
open (LOG, ">>" .$opt{l});
my $sess = Expect->spawn("telnet $ip");
my $fh = *LOG;
$sess->log_file($fh)
Now, I get a file named *main::LOG
in the directory. I do have another file as well, named whatever I specified on the -l
option, but it only contains the lines that I send to print LOG
.
I'm not sure if the filehandling functionality is hosed in the function, or if I'm doing something wrong.