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. |