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

I am looking to eventually only retrieve the FileVersion portion of Win32::Exe but something isn't working well.

#!/usr/bin/perl use Win32::Exe qw( ); my $remexe ='C:\Users\some.exe'; $remexe =~ tr|\\|/|; my $exe = Win32::Exe->new($remexe); $exe = $exe->create_resource_section if $exe->can_create_resource_sect +ion; my $info = $exe->get_version_info; print qq($_ = $info->{$_}\n) for (sort keys(%$info));

Works (but it sure takes a long time) once.
The second or third time, I get the dreaded Out of Memory!

%perl -e "print $^X" \Perl\bin\perl.exe %perl -V Summary of my perl5 (revision 5 version 24 subversion 1) configuration +: Platform: osname=MSWin32, osvers=6.1, archname=MSWin32-x86-multi-thread-64in +t uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef useithreads=define, usemultiplicity=define use64bitint=define, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='C:\STRAWB~1\c\bin\gcc.exe', ccflags =' -s -O2 -DWIN32 -DPERL_T +EXTMODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IM +PLICIT_SYS -fwrapv -fno-strict-aliasing -mms-bitfields', optimize='-s -O2', cppflags='-DWIN32' ccversion='', gccversion='4.6.3', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678 +, doublekind=3 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +2, longdblkind=3 ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='lo +ng long', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='C:\STRAWB~1\c\bin\g++.exe', ldflags ='-s -static-libgcc -stati +c-libstdc++ -L"C:\Perl\lib\CORE" -L"C:\MinGW\i686-w64-mingw32\lib"' libpth=C:\MinGW\i686-w64-mingw32\lib libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 +-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -l +mpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdl +g32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_3 +2 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 libc=, so=dll, useshrplib=true, libperl=libperl524.a gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-mdll -s -static-libgcc -static-libstdc +++ -L"C:\Perl\lib\CORE" -L"C:\MinGW\i686-w64-mingw32\lib"' Characteristics of this binary (from libperl): Compile-time options: HAS_TIMES HAVE_INTERP_INTERN MULTIPLICITY PERLIO_LAYERS PERL_COPY_ON_WRITE PERL_DONT_CREATE_GVSV PERL_HASH_FUNC_ONE_AT_A_TIME_HARD PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS PERL_MALLOC_WRAP PERL_PRESERVE_IVUV USE_64_BIT +_INT USE_ITHREADS USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_PERLIO USE_PERL_ATOF USE_SITECUSTOMIZE Locally applied patches: ActivePerl Build 2402 [401627] Built under MSWin32 Compiled at Jan 5 2017 01:57:19 @INC: C:/Perl/site/lib C:/Perl/lib .

I cant believe Im out of memory, and cant understand why it takes over 60 seconds..
Im on an 2.4 gig i7 with 8GB ram.. but sure enough, running that simple script eats every last bit of available memory

Any ideas ?

Replies are listed 'Best First'.
Re: Out of memory Win32::Exe
by Athanasius (Archbishop) on Jan 26, 2017 at 03:01 UTC

      Well, poop... And I though I looked for current bug reports...

      Any suggestions for alternatives ?
      Thanks for responding so quickly as well...

        Did you follow the link? Did you not see the author's suggested alternative for your requirement? (ie. Win32::File::VersionInfo )

Re: Out of memory Win32::Exe
by GrandFather (Saint) on Feb 08, 2017 at 20:03 UTC

    Sorry, kinda late to the party, but you may find Win32::PEFile helpful. The current CPAN version doesn't provide resource creation and editing, but a version I have sitting in the wings does. Prod me via /msg if you are keen on the update - I've a few other things on the go that I need to sort out first though.

    #!/usr/bin/perl use strict; use warnings; use Win32::PEFile; my $pe = Win32::PEFile->new(-file => 'C:\Perl\bin\perl.exe'); my $verStrs = $pe->getVersionStrings(); print "$_: '$verStrs->{$_}'\n" for keys %$verStrs;

    Prints:

    CompanyName = 'ActiveState' FileDescription = 'Perl Command Line Interpreter' FileVersion = '5,16,3,1603' InternalName = 'perl.exe' LegalCopyright = 'Copyright 1987-2011, Larry Wall, Binary build by Act +iveState, http://www.ActiveState.com' LegalTrademarks = '' OriginalFilename = 'perl.exe' ProductName = 'ActivePerl' ProductVersion = 'Build 1603 [296746]'
    Premature optimization is the root of all job security