The following code telnets to google and saves the "expect" log to a file. That is, as long as I don't spawn a thread before I spawn my Expect object! If I define $make_it_break to 1, this code will only save to the logfile the strings I send.
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; } }
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?

Thanks,
Dave

In reply to Is there a workaround for threads breaking Expect.pm logging? by knave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.