knave has asked for the wisdom of the Perl Monks concerning the following question:
Unfortunately, in my application, I need to spawn a thread before spawning my telnet session. I also need automatic expect logging. Is there any workaround for me?use Expect; use FileHandle; use threads; my $telnet = new Expect; my $telnet_logfile_name = "telnet.log"; my $telnet_logfile = new FileHandle (">$telnet_logfile_name") or die " +Can't write $telnet_logfile_name! $!"; $telnet_logfile->autoflush(1); $telnet->log_file (sub { my $str=shift; $telnet_logfile->print ("$str +"); }); my @command = qw(telnet www.google.com 80); my $make_it_break = 0; if ($make_it_break) { threads->new (\&daves_handler); $telnet->spawn (@command) or die "Cannot spawn @command: $!\n"; } else { $telnet->spawn (@command) or die "Cannot spawn @command: $!\n"; threads->new (\&daves_handler); } $telnet->send ("GET / HTTP/1.1\r\nUser-Agent: dave\r\nHost: www.google +.com\r\n\r\n"); $telnet->expect (10, 'HTTP/1.1 200 OK'); $telnet->print_log_file("Dave was here\n"); sub daves_handler { while (1) { sleep 10; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is there a workaround for threads breaking Expect.pm logging?
by merlyn (Sage) on Jul 30, 2005 at 01:37 UTC | |
by knave (Acolyte) on Aug 01, 2005 at 18:03 UTC | |
|
Re: Is there a workaround for threads breaking Expect.pm logging?
by mrborisguy (Hermit) on Jul 30, 2005 at 00:31 UTC | |
by knave (Acolyte) on Aug 01, 2005 at 18:13 UTC |