A more sophisticated way to do it in Windows is with Win32::Process::Create:
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!"; }
$obj and $code are simply scalars that will be populated with the object used to get the exit code and the exit code.

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 :-)


In reply to Re: How do I run a .bat file? by Starky
in thread How do I run a .bat file? by Etelka

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.