I don't think there is a way to access ERRORLEVEL from a Perl script to check what the ERRORLEVEL is *before* starting the Perl script. You can access it after calling a command with 'system', such as:

# successful command and exit code system ('dir'); print qq(ERR Code = $?\n); # UN-successful command and exit code system ('dri'); print qq(ERR Code = $?\n);
Note, ERRORLEVEL is a "special" Windows environment variable:

C:> set /? [...] If Command Extensions are enabled, then there are several dynamic envi +ronment variables that can be expanded but which don't show up in the + list of variables displayed by SET. These variable values are compu +ted dynamically each time the value of the variable is expanded. If t +he user explicitly defines a variable with one of these names, then that definition will override the dynamic one described below: %CD% - expands to the current directory string. %DATE% - expands to current date using same format as DATE command. %TIME% - expands to current time using same format as TIME command. %RANDOM% - expands to a random decimal number between 0 and 32767. %ERRORLEVEL% - expands to the current ERRORLEVEL value %CMDEXTVERSION% - expands to the current Command Processor Extensions +version number. %CMDCMDLINE% - expands to the original command line that invoked the C +ommand Processor.
You can try to get around this. Are you using pl2bat to get your Perl scripts to run on Windows? Just edit the resulting batch script to include a conditional:

if %ERRORLEVEL% 2 perl -x -S %0 %*
Where '2' above is the desired ERRORLEVEL, or use 'if NOT %ERRORLEVLE% ...' to get the opposite effect.

What launches your Perl script? Is it a batch file? What is the command that's running before it? Perhaps there is a way to include the conditional check for the ERRORLEVEL in that "thing" that launches your Perl script.


In reply to Re: access to ERRORLEVEL on Win32 by VinsWorldcom
in thread access to ERRORLEVEL on Win32 by gkraus

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.