Hi monks,

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>
I post this question on Inline and Sisyphus (many Thanks! Sisyphus) replied me and suggest me posting this question on perlmonks for help. here is his reply:
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&#9508;aæ&#9787;&#8593;:ñ $ &#8593;:ñ ~&#8593;&#9787; 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ð¬&#9472;w4§Å &#8593; 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


In reply to odd line in windows by xiaoyafeng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.