Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 31st, 2001, 09:58 AM
bteravsk bteravsk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Minneapolis, MN
Posts: 0 bteravsk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old July 31st, 2001, 10:46 AM
bteravsk bteravsk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Minneapolis, MN
Posts: 0 bteravsk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Help with array of objects


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT