in reply to How do I run a .bat file?
$obj and $code are simply scalars that will be populated with the object used to get the exit code and the exit code.Win32::Process::Create( $obj, 'c:\path\to\batch\file\myfile.bat', 'myfile arg1 arg2', 0, NORMAL_PRIORITY_CLASS, 'c:\this\will\be\the\working\directory' ) || die(Win32::FormatMessage( Win32::GetLastError() )); $obj->Wait(2000); $obj->GetExitCode($code); print STDERR "The exit code is $code."; if ($code == 259) { warn "The batch file did not terminate after 2 seconds!"; }
Using Win32::Process will give you more reliable access to exit codes than system() or backticks. I believe that you can now get exit codes with the normal method with backticks (don't quote me) but that used to not be the case. The module also give you greater flexibility in your system call.
Check out the Win32::Process docs for more information.
Note that it's been a couple years since I used Windows (I started using Linux a couple years ago and haven't looked back), so my knowledge of the Win32::Process modules is a little rusty. However, I do recall that at the time, Win9x and WinNT differed in their behavior, so I had to write conditionals to account for those differences in many cases. Go figure.
Hope this helps :-)
|
|---|