CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
memory issue with my script

 



lukdk
Novice

Jun 19, 2012, 9:01 AM

Post #1 of 5 (1440 views)
memory issue with my script Can't Post

Hello,


I'm having an issue with trying to run a script. It runs for a while, gathers information for some time untill i get the error message: Out of memory!

When i check my task manager i see perl.exe keeps taking more and more momory (over 100MB), unless i comment out the following line:


Code
print RESULT "$computer	",&versioncheck("\\\\$computer\\c\$\\windows\\system32\\msi.dll"),"\n";


This line is used in a ending loop. If I comment this out, perl.exe only uses around 9MB which seems more realistic.

This is the code for the sub:


Code
use Win32::Exe qw(); 
sub versioncheck{
my $exe = Win32::Exe->new(@_);
my @exe = $exe->version_info->get('FileVersion');
return $exe[0];
}



(This post was edited by lukdk on Jun 19, 2012, 9:02 AM)


wickedxter
User

Jun 24, 2012, 5:45 PM

Post #2 of 5 (1412 views)
Re: [lukdk] memory issue with my script [In reply to] Can't Post

This should work as i think you wanted it to.


Code
 

use Win32::Exe qw();
use strict;
use warnings;

my @files = ('c:\some\where\','c:\somewhere\else');

print versioncheck(\@files);

sub versioncheck{
#this supports an array of files to search
for my $file (@_){
my $exe = Win32::Exe->new($file);
return $exe->version_info->get('FileVersion');
}
}



lukdk
Novice

Jun 25, 2012, 6:59 AM

Post #3 of 5 (1397 views)
Re: [wickedxter] memory issue with my script [In reply to] Can't Post

Hello,

Thanks for the feedback, although the problem is I don't know the array of files to check when i start the script.

The problem here is that i'm collecting information on remote computers, not knowing weather or not they are powered on. By the time the script finds out which of the 10K+ computers are online, the information is already outdated. That's why the idea is to check if a computer is online and gather information from one computer at a time.

I've looked on the web for other methods and i found the module Win32::File::VersionInfo. I don't know yet if this would solve the memory issue. I do know i had a problem transfering my parameters to that other sub: my $file=GetFileVersionInfo (@_); doesn't work. I'm calling this sub exactly the same way as in the first post.




Code
 use Win32::File::VersionInfo; sub versioncheck{    
my $file=GetFileVersionInfo ("c:\\windows\\system32\\msi.dll");
if ($file){
return $file->{'FileVersion'}, "\n";
# return $file->{FileVersion};
} else {
return 0;
}
}



I've looked up information on perl constructors / destructors, but no good luck there as well.

adding this in the first example didn't help either:

$exe=undef;
my $temp=$exe[0];
@exe=undef;
return $temp;


(This post was edited by lukdk on Jun 25, 2012, 7:13 AM)


FishMonger
Veteran / Moderator

Jun 25, 2012, 9:50 AM

Post #4 of 5 (1383 views)
Re: [lukdk] memory issue with my script [In reply to] Can't Post

I have not tested this on a large dataset, but works ok on a small list.

Code
#!/usr/bin/perl 

use strict;
use warnings;
use Win32::File::VersionInfo;

my @servers = qw(fishmonger foo bar);
my $file = 'c$\windows\system32\msi.dll';

foreach my $server (@servers) {
my $path = "\\\\$server\\$file";
print "$path\n";

my $file_info = versioncheck($path);
if ($file_info) {
print "\t$file_info\n";
}
else {
print "\tfile is unreachable\n";
}
}

sub versioncheck {
my $path = shift;
my $file_info = GetFileVersionInfo($path);
if ($file_info) {
return $file_info->{'FileVersion'};
}
else {
return 0;
}
}



lukdk
Novice

Jun 29, 2012, 5:44 AM

Post #5 of 5 (1285 views)
Re: [FishMonger] memory issue with my script [In reply to] Can't Post

Hello,

This did fix the memory issue.

I assume we can conclude there is a bug in the Win32::Exe module?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives