First, find a little background about exit code in perl (also here)and on Windows.
Now - when I execute another process from a perl script (I'm open as to the method, qx
/open
/system
/exec
/IPC::Run
, etc.) on Windows:
is it possible to capture exit codes outside the range of 0
- 255
?
On Windows, a process can return a full (signed) 32bit exit code, and it's not so uncommon to have something return 0x8...0...
, that is, some COM error code or somesuch.
Yes, Win32::Process can return the full signed 32-bit exit code. Use the GetExitCode
method. But it's a little tricky, because the return value is not the exit code (it's the return value of the Windows GetExitCodeProcess function, which indicates success or failure of the function). The exit code gets stored into the variable you pass to the method.
use Win32::Process;
use Win32;
sub ErrorReport{
print Win32::FormatMessage( Win32::GetLastError() );
}
my $ProcessObj;
Win32::Process::Create($ProcessObj,
"C:\\winnt\\system32\\notepad.exe",
"notepad temp.txt",
0,
NORMAL_PRIORITY_CLASS,
".") or die ErrorReport();
$ProcessObj->Wait(INFINITE);
my $exitCode;
$ProcessObj->GetExitCode($exitCode) or die ErrorReport();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With