Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
The documentation is inaccurate and the code is buggy. From http://search.cpan.org/src/JDB/libwin32-0.26/Process/Process.xs:
So, RETVAL isn't initialized so if OpenProcess() fails, RETVAL will be random garbage from the stack (some "large number", as observed, or sometimes 0 or 1, unfortunately, I guess -- unless the "arbitrary" observation is inaccurate and it is actually a standard Win32 marker value like 0xCCCCCCCC). If OpenProcess() succeeds, then RETVAL will say whether or not TerminateProcess() was successful or not. And exitcode is not an output parameter so it isn't set to anything. It specifies what exit code the terminated process will use (as documented in the Win32 SDK). Luckily, both OpenProcess() and TerminateProcess() call SetLastError() (Win32 SDK again) so you can check $^E to see if they failed (if you do it fast enough). For example:
But someone should really fix the docs and code for this module, especially since it leaks a process handle if TerminateProcess() fails. - tye In reply to Re^2: Killing a Win32 process, a return value ? (bugs)
by tye
|
|