LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-07-2011, 03:41 PM   #1
gothrog
Member
 
Registered: Jun 2004
Distribution: Yellow Dog, Fedora, RedHat, Centos, Ubuntu, Suse Linux
Posts: 106

Rep: Reputation: 15
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->'
 
Old 07-08-2011, 08:48 AM   #2
gothrog
Member
 
Registered: Jun 2004
Distribution: Yellow Dog, Fedora, RedHat, Centos, Ubuntu, Suse Linux
Posts: 106

Original Poster
Rep: Reputation: 15
All, I think I might have found my problem. I think it has to do with not having enough priority to run and is causing it's self to crash.

Related post dealing with foreground vs background processes.
http://www.linuxquestions.org/questi...=1#post4408781
 
Old 07-08-2011, 09:46 AM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Perl questions are best dealt with at http://www.perlmonks.org.
 
Old 07-08-2011, 12:04 PM   #4
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Quote:
Originally Posted by sundialsvcs View Post
Perl questions are best dealt with at http://www.perlmonks.org.
The link doesn't work for me, but http://perlmonks.org/ works just fine.

Markus
 
Old 07-11-2011, 11:51 AM   #5
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
This perl-Expect module can help you out.

Last edited by vikas027; 07-11-2011 at 12:10 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PERL expect o/p AlbertJJ Programming 4 07-29-2011 03:15 AM
[SOLVED] perl-Expect module to exit if in case of ssh failure vikas027 Programming 1 07-11-2011 11:50 AM
Perl without threads support dunric Slackware 1 06-08-2007 07:00 PM
[Perl] Expect.pm local passwd change noir911 Programming 3 02-16-2007 07:30 AM
Help Compile perl with threads sendas Linux - Newbie 1 12-24-2006 07:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration