|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with array of objects
Hello,
I'm trying to create a perl script on a Windows NT system that will kick of a variable number of processes to due a parallel attack at a task. I'm using the Win32::Process module. My thinking is to create an array of objects that reference each process that will be executed. Here is what I tried: #----------------------------------- use Win32::Process; my @ProcessObj = (); print "Starting process 1\n"; Win32::Process::Create($ProcessObj[0], "c:/Perl/bin/perl.exe", "perl P:/Programs/routertable/process/testproc.pl 1", 0, DETACHED_PROCESS, ".") || die "Cannot create process\n"; # print "Starting process 2\n"; Win32::Process::Create($ProcessObj[1], "c:/Perl/bin/perl.exe", "perl P:/Programs/routertable/process/testproc.pl 2", 0, DETACHED_PROCESS, ".") || die "Cannot create process\n"; print "$#ProcessObj\n"; $ProcessObj[0]->Wait(INFINITE); # sleep(1); $ProcessObj[0]->GetExitCode($exitcode); print "test.pl: Exit code: $exitcode\n"; exit; #------------------------ When I run the script I get the following error: P:\Programs\routertable\process>perl test.pl Starting process 1 Starting process 2 -1 Can't call method "Wait" on an undefined value at test.pl line 21. Is there a way that I can create an array of Win32::Process objects to do this. Thanks in advance. Brian |
|
#2
|
|||
|
|||
|
It's always amazing... Work on this for a few days on and off for a few days with no progress, post a question, work a little more and amazingly a breakthrough.
I guess you have to push the reference into the list. Here is the example that worked for me: ----------------------------------- use Win32::Process; my @ProcessObj = (); my $Obj; for ($i = 0; $i < 3; $i++) { N = $i + 1; print "Starting process $N: "; Win32::Process::Create($Obj, "c:/Perl/bin/perl.exe", "perl P:/Programs/routertable/process/testproc.pl $N", 0, DETACHED_PROCESS, ".") || die "Cannot create process\n"; # print ref($Obj)."\n"; print "$Obj\n"; push @ProcessObj, $Obj; } print "$#ProcessObj: "; for ($j = 0; $j < 3; $j++) { print "$ProcessObj[$j]"; } print "\n"; $ProcessObj[1]->Wait(INFINITE); $ProcessObj[1]->GetExitCode($exitcode); print "test.pl: Exit code: $exitcode\n"; exit; ----------------------------- Output looks like this now: P:\Programs\routertable\process>perl test.pl Starting process 1: Win32::Process Win32::Process=SCALAR(0x1a7f114) Starting process 2: Win32::Process Win32::Process=SCALAR(0x1a754d0) Starting process 3: Win32::Process Win32::Process=SCALAR(0x1beb4bc) 2: Win32::Process=SCALAR(0x1a7f114)Win32::Process=SCALAR(0x1a754d0)Win32::Process=SCALAR(0x1beb4bc) test.pl: Exit code: 2 Sorry to waste bandwidth. I hope someone else can use what I did to solve this. Regards, Brian |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Help with array of objects |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|