Hi, I had same problem as you, so I created own spawn subroutine, with more pseudoterminals. I using it for parallel connection to servers:

Constructor:

sub new { my $class = shift; my $self = {}; bless $self, $class; my $log = Log::Log4perl->get_logger("$class"); $self->{LOGGER} = $log; my $pty = $self->spawn("/bin/bash"); # spawn() defined below $self->{PTY} = $pty; my $exp = Expect->exp_init($pty); my $ref = $exp->expect(TIMEOUT, [ $shell_prompts ] ); if (!$ref){ $log->warn("Timeout received!"); return -1; } $exp->clear_accum(); #$exp->log_stdout(1); $exp->raw_pty(1); #$exp->debug(3); $Expect::Multiline_Matching = 0 ; $self->{EXPECT} = $exp; $log->debug("Creating instance $class"); return $self; }
SPAWN subroutine:
sub spawn { my($cmd) = @_; my($pid, $pty, $tty, $tty_fd); ## Create a new pseudo terminal. $pty = new IO::Pty or die $!; ## Execute the program in another process. unless ($pid = fork) { # child process die "problem spawning program: $!\n" unless defined $pid; ## Disassociate process from existing controlling terminal. use POSIX (); POSIX::setsid or die "setsid failed: $!"; ## Associate process with a new controlling terminal. $tty = $pty->slave; $pty->make_slave_controlling_terminal(); $tty_fd = $tty->fileno; close $pty; ## Make stdio use the new controlling terminal. open STDIN, "<&$tty_fd" or die $!; open STDOUT, ">&$tty_fd" or die $!; open STDERR, ">&STDOUT" or die $!; close $tty; ## Execute requested program. exec "/bin/bash" #exec $cmd or die "problem executing /bin/bash\n"; } # end child process return $pty; } # end sub spawn
Then you can create new expect process in you each child in your main method :
my $pm = new Parallel::ForkManager(5); for (1...10) { my $pid = $pm->start and next; my $exp = Expect_common->new(); # expect send ... # $pm->finish; # Terminates the child process } $pm->wait_all_children;

In reply to Re: Using Perl Threads with Expect.pm by olibertu
in thread Using Perl Threads with Expect.pm by vishi

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.