jiwei800715 has asked for the wisdom of the Perl Monks concerning the following question:

I have two programs working on win32 system program 1: Create a TXT File and write data
$FH = FileHandle::Rollback->new("> $filepath") or die "cannot open fil +ehandle: $!"; select($FH); for my $i(0..$#{$temp_array1[0]}) { my $stringline=join(" ",@{$temp_array1[0]->[$i]}); print("$stringline \n"); } $FH->commit;
program2 : read TXT files and write them in one bin file
opendir(my $FILELIST,"temp")|| die $_; while(my $filename=readdir($FILELIST)) { my @temp_ref=grep{($_->{SecID}.substr($_->{Date},0,4).subs +tr($_->{Date},5,2).substr($_->{Date},8,2).".TXT") eq $filename}@Task_ +list; my $TaskRef=$temp_ref[0]; if((-e-r $TXTfilepath.$filename)&&defined($TaskRef)) { &writebin($TaskRef) } }
usually, I run program2 when program1 is finished, but now it is a need to run both on the same time,which means we need interprocess comunication between these two programs. I dont want to connect them in threads way, It is not stable on windows Xp . Is there any easy way to send task from program1 to program2 ,and let program2 waiting for task? thanks

Replies are listed 'Best First'.
Re: send info between 2 programs
by Anonymous Monk on Mar 17, 2009 at 10:02 UTC
      I try to use Thread::Queue to send info, but when join this thread, it leads to a error " Free to wrong Pool", I followed some topics about this error, cannot find any reasonable explanation, except for use of win32::ole
      our @Task_list; our ($DataQueue1,$DataQueue2); my $ExcelFile='D:\HF_project_perl\Update.xls'; #this use win32:ole to read excel @Task_list=Create_TaskList($ExcelFile); print "Create TaskList"; #Create 2 Queues $DataQueue1-- Main thread to thread1; #$DataQueue2-- +-therad1 to thread2 $DataQueue1 = Thread::Queue->new(); $DataQueue2 = Thread::Queue->new(); my $thr1 = threads->create(\&thread1); print "set up thread1 \n";#for debug my $thr2 = threads->create(\&thread2); print "set up thread2 \n"; #for debug #Assign Task to thread1 by $DataQueue1 for my $i (0..$#Task_list){ $DataQueue1->enqueue($Task_list[$i]); print "send task $i to Thread1 \n"; #for debug print "wait 10s \n"; sleep(10); } #Task completed Flag $DataQueue1->enqueue(undef); print "send undef to stop T1 "; $thr2->join(); $thr1->join(); sub thread1{ my $TaskRef; my $Taskcounter; while ( defined($TaskRef = $DataQueue1->dequeue())) { $Taskcounter++; my $SecID=$TaskRef->{SecID}; my $Date=$TaskRef->{Date}; print "Thread1 finish task $Taskcounter"; print "$SecID $Date \n"; $DataQueue2->enqueue($TaskRef); # notify thread2 to follow the task, Assign Task to thead2 by $DataQue +ue2 print "Send task $Taskcounter to T2 \n";#for debug print "T1 wait 2s \n"; sleep(2); } $DataQueue2->enqueue(undef);#Task completed Flag select(STDOUT); print "T1 stop and inform T2 to stop \n"; #for debug } sub thread2{ my $TaskRef; my $Task_Finished_counter=0; while ( defined($TaskRef = $DataQueue2->dequeue()) ) { print "Thread2 finish task $Task_Finished_counter"; print "$TaskRef->{SecID} $TaskRef->{Date} \n"; #for debug } print "T2 stop \n"; #for debug }
      a easy example for threads way, error "Free to wrong Pool" happens when join the thread , why ?