Hi, I have the following code to list the running PIDs on a Windows machine. It uses the Win32::API module.
You will notice that use strict; is commented out. The reason is that when I uncomment use strict; I get the following error,#! /usr/bin/perl #use strict; use warnings; use Win32::API; #define some constants my $DWORD_SIZE = 4; my $PROC_ARRAY_SIZE = 300; my $MODULE_LIST_SIZE = 300; #define some Win32 API constants my $PROCESS_QUERY_INFORMATION = 0x0400; my $PROCESS_VM_READ = 0x0010; my $enum_proc = new Win32::API( 'psapi.dll', 'EnumProcesses', [P,N, +P], I ) || die "Cannot Enum Processes: $!\n"; #Create a Buffer Array my $proc_array = &MakeBuffer($DWORD_SIZE * $PROC_ARRAY_SIZE); my $proc_num = &MakeBuffer($DWORD_SIZE); if (0 != $enum_proc->Call($proc_array, $PROC_ARRAY_SIZE, $proc_num)) { $proc_num = unpack ("L", $proc_num) / $DWORD_SIZE; print "\$proc_num = $proc_num\n"; my @pid_lst = unpack("L$proc_num", $proc_array); foreach my $pid(@pid_lst) { print "$pid - Running\n"; } } sub MakeBuffer { my ($buffer_size) = @_; return("\x00" x $buffer_size); }
Any ideas how I can still use strict and line 17 together..? I got most of this code from Dave Roths Win32 Perl Scripting book. -----Bareword "P" not allowed while "strict subs" in use at C:\dev\Source_P +erl\MiscTests\pid\roth.pl line 17. Bareword "N" not allowed while "strict subs" in use at C:\dev\Source_P +erl\MiscTests\pid\roth.pl line 17. Bareword "P" not allowed while "strict subs" in use at C:\dev\Source_P +erl\MiscTests\pid\roth.pl line 17. Bareword "I" not allowed while "strict subs" in use at C:\dev\Source_P +erl\MiscTests\pid\roth.pl line 17. Execution of C:\dev\Source_Perl\MiscTests\pid\roth.pl aborted due to c +ompilation errors.
In reply to use strict and Win32::API by AcidHawk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |