ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Yellow Dog, Fedora, RedHat, Centos, Ubuntu, Suse Linux
Posts: 106
Rep:
Perl Threads and Expect
All,
I have perl and expect working together, however now I wanted to put that routine into a perl script.
I'm getting this "Closing spawn id(3)." error. I'm not sure why I can't launch this same routine within a perl thread.
Does anyone have any idea what I need to add to the perl thread? This is my first experience with perl threads.
Some Code:
Code:
use warnings;
use Expect;
use threads();
use threads::shared;
my $exp :shared = 0;
my $thr1 = threads->create(\&expect_thread, "test1");
$thr1->join();
# Part of routine
sub expect_thread
{
print('Thread started: ', join(' ', @args), "\n");
$filename = "MY.xml";
$timeout = undef;
# Loop
$expectFlag = 1;
while ( $expectFlag == 1)
{
my $exp = new Expect;
# $exp = new Expect;
$exp->raw_pty(0);
$exp->exp_internal(1);
$exp->debug(2);
$exp->log_file("expectLog.txt");
$exp->log_stdout(1);
my $fileContents = "";
my $checkPos = 0;
$exp->spawn($julexe);
$runFlag = 1;
while ( $runFlag == 1 )
{
$patidx = $exp->expect($timeout, 'enter filename->'); <----- Fails here
..............
Error:
Code:
Starting EXPECT pattern matching...
at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 559
Expect::expect('Expect=GLOB(0x453f360)', 'undef', 'enter filename->') called at perlExpectJuliusIM_FOREVER.pl line 73
main::expect_thread('test1') called at perlExpectJuliusIM_FOREVER.pl line 120
eval {...} called at perlExpectJuliusIM_FOREVER.pl line 120
spawn id(3): list of patterns:
#1: -ex `enter filename->'
spawn id(3): Does `'
match:
pattern #1: -ex `enter filename->'? No.
Closing spawn id(3).
at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1415
Expect::hard_close('Expect=GLOB(0x453f360)') called at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 878
Expect::_multi_expect('undef', 'undef', 'ARRAY(0x45981f0)') called at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 563
Expect::expect('Expect=GLOB(0x453f360)', 'undef', 'enter filename->') called at perlExpectJuliusIM_FOREVER.pl line 73
main::expect_thread('test1') called at perlExpectJuliusIM_FOREVER.pl line 120
eval {...} called at perlExpectJuliusIM_FOREVER.pl line 120
spawn id(3) closed.
Pid 23657 of spawn id(3) terminated, Status: 0x01
Use of uninitialized value in numeric eq (==) at perlExpectJuliusIM_FOREVER.pl line 77.
Starting EXPECT pattern matching...
at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 559
Expect::expect('Expect=GLOB(0x453f360)', 'undef', 'enter filename->') called at perlExpectJuliusIM_FOREVER.pl line 73
main::expect_thread('test1') called at perlExpectJuliusIM_FOREVER.pl line 120
eval {...} called at perlExpectJuliusIM_FOREVER.pl line 120
spawn id(3): list of patterns:
#1: -ex `enter filename->'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.