Several points here. First of all, you have not shown us the code where you "invoke the perl script", but the code where you invoke portableshell.bat
file, and you did not show us the contents of such Batch file. So the first and simplest way to solve your problem is:
1- Insert in your windows Batch file the same command you use to "invoke the perl script" in the C:\Strawberry32\portableshell.bat
file. This will give access to the errorlevel from the perl script for sure.
I assume that the contents of portableshell.bat
file are basically two lines: the one that run the perl script followed by this line:
exit /B %errorlevel%
The purpose of previous line is to return the errorlevel from the perl script to the Batch file that called this one Batch file. This mechanism works perfectly as long as this Batch file be called via call
command:
2- Invoke the C:\Strawberry32\portableshell.bat
file via a call
command:
call C:\Strawberry32\portableshell.bat C:\Users\abc\error.pl
If the portableshell.bat
file is invoked via cmd /c
instead of call
, then you must set the returning errorlevel of cmd.exe program via a plain exit
command, with NO /B
switch:
3- Invoke the C:\Strawberry32\portableshell.bat
file via cmd /c
line, but terminate it with this command:
exit %errorlevel%
You may read a further explanation of the errorlevel stuff and the differences of exit /B number
vs exit number
at What are the ERRORLEVEL values set by internal cmd.exe commands?. At that site you may read that a start /B /WAIT portableshell.bat
command may also be used to solve this problem, but this method also requires to end the .bat file with exit %errorlevel%
in the same way as the cmd /c
method.