xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:
I wrote a simple snippet to list processes name and pid on windows. but the output returns a strange line. below is the code:
use strict; use warnings; use Inline C => DATA => LIBS => '-luser32 -lkernel32 -lpsapi'; my $a = process_list(); map { print; print get_proc_name($_);print "\n"; } @{$a}; __END__ __C__ #include <windows.h> #include <stdio.h> #include <tchar.h> #include <psapi.h> char* get_proc_name( int processID ) { TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>"); HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); if (NULL != hProcess ) { HMODULE hMod; DWORD cbNeeded; if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ) { GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName)/sizeof(TCHAR) ); } } CloseHandle( hProcess ); return szProcessName; } SV* process_list(){ DWORD aProcesses[1024], cbNeeded, cProcesses; unsigned int i; EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ); cProcesses = cbNeeded / sizeof(DWORD); AV* AV_procs = newAV(); for ( i = 0; i < cProcesses; i++ ) { if( aProcesses[i] != 0 ) { av_push(AV_procs, newSViv( aProcesses[i] ) ); } } return newRV_inc(AV_procs); } __OUTPUT__ C:\>perl test.pl 4P ?F > <== strange line 292<unknown> 372<unknown> 432<unknown>
Haven't yet had a chance to take a thorough look at this. I inserted the following near the beginning of your script: use Inline C => Config => BUILD_NOISY => 1; That way you get to see any compiler warnings that are emitted during +the C compilation, and with my cc-4.5.2 build of perl-5.14 I saw: try_pl_f4a3.xs: In function 'get_proc_name': try_pl_f4a3.xs:35:1: warning: function returns address of local variab +le try_pl_f4a3.xs: In function 'process_list': try_pl_f4a3.xs:57:5: warning: passing argument 2 of 'Perl_newRV' from +incompatible pointer type C:\MinGW\perl\lib\CORE/proto.h:2567:19: note: expected 'struct SV * co +nst' but argument is of type 'struct AV *' Whether there's anything relevant there, I don't know. I get different output to you, of course. But in the middle of the out +put I also got one odd-looking line: 1348┤aæ☻↑:ñ $ ↑:ñ ~↑☻ When I switched to a gcc-3.4.5 build of perl-5.12, I found out what 13 +48 really was: 1348TomTomHOMERunner.exe But then I got a strange line at the beginning of the output: 4ð¬─w4§Å ↑ whereas, with gcc-4.5.2, that had been: 4<unknown>
Thanks in advance!!!
I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: odd line in windows
by BrowserUk (Patriarch) on Sep 07, 2011 at 07:52 UTC | |
by xiaoyafeng (Deacon) on Sep 07, 2011 at 09:22 UTC | |
by BrowserUk (Patriarch) on Sep 07, 2011 at 09:39 UTC | |
by Anonymous Monk on Sep 07, 2011 at 09:27 UTC | |
by syphilis (Archbishop) on Sep 07, 2011 at 15:14 UTC | |
by BrowserUk (Patriarch) on Sep 07, 2011 at 15:37 UTC | |
by syphilis (Archbishop) on Sep 07, 2011 at 16:30 UTC | |
|
Re: odd line in windows
by syphilis (Archbishop) on Sep 07, 2011 at 16:06 UTC | |
by xiaoyafeng (Deacon) on Sep 08, 2011 at 07:49 UTC | |
by ikegami (Patriarch) on Sep 08, 2011 at 09:26 UTC | |
by syphilis (Archbishop) on Sep 08, 2011 at 10:58 UTC | |
by BrowserUk (Patriarch) on Sep 08, 2011 at 11:12 UTC | |
| |
by ikegami (Patriarch) on Sep 09, 2011 at 03:20 UTC | |
by ikegami (Patriarch) on Sep 08, 2011 at 19:53 UTC | |
by ikegami (Patriarch) on Sep 08, 2011 at 07:13 UTC |