Skip to content

Commit 4331b33

Browse files
nvpbrowngenio
authored andcommitted
Update portableshell.bat to return exit code from Perl invocations.
This change modifies the non-interactive path in portableshell.bat (where it invokes Perl with all provided arguments) to return the exit code from the Perl process via "exit /b %ERRORLEVEL%" to the caller. Prior to this change, using "portableshell.bat" in place of "perl.exe" to run commands like: portableshell.bat script.pl arg1 arg2 would return with an exit code of zero, which is problematic if you want to use the batch file in a makefile recipe or in some other environment where you need to take additional actions based on the Perl script's exit code.
1 parent d1a3c70 commit 4331b33

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

share/portable/portableshell.bat

+13-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,19 @@ set PERL_MB_OPT=
1414

1515
if "%1" == "/SETENV" goto END
1616

17-
if not "%1" == "" "%~dp0perl\bin\perl.exe" %* & goto ENDLOCAL
18-
17+
if "%1" == "" goto INTERACTIVE
18+
19+
REM For non-interactive invocations of this batch file, run Perl with all
20+
REM provided argument and return its exit code. Clear the ERRORLEVEL
21+
REM variable in our local environment to ensure our "exit /b" statement
22+
REM returns the error level from Perl even if there is already an ERRORLEVEL
23+
REM variable in the environment:
24+
REM https://devblogs.microsoft.com/oldnewthing/20080926-00
25+
set ERRORLEVEL=
26+
"%~dp0perl\bin\perl.exe" %*
27+
exit /b %ERRORLEVEL%
28+
29+
:INTERACTIVE
1930
echo ----------------------------------------------
2031
echo Welcome to Strawberry Perl Portable Edition!
2132
echo * URL - http://www.strawberryperl.com/

share/portable/portableshell.pdl.bat

+13-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,19 @@ set PERL_MB_OPT=
1717

1818
if "%1" == "/SETENV" goto END
1919

20-
if not "%1" == "" "%~dp0perl\bin\perl.exe" %* & goto ENDLOCAL
21-
20+
if "%1" == "" goto INTERACTIVE
21+
22+
REM For non-interactive invocations of this batch file, run Perl with all
23+
REM provided argument and return its exit code. Clear the ERRORLEVEL
24+
REM variable in our local environment to ensure our "exit /b" statement
25+
REM returns the error level from Perl even if there is already an ERRORLEVEL
26+
REM variable in the environment:
27+
REM https://devblogs.microsoft.com/oldnewthing/20080926-00
28+
set ERRORLEVEL=
29+
"%~dp0perl\bin\perl.exe" %*
30+
exit /b %ERRORLEVEL%
31+
32+
:INTERACTIVE
2233
echo ----------------------------------------------
2334
echo Welcome to Strawberry Perl PDL Edition!
2435
echo * URL - https://strawberryperl.com + http://pdl.perl.org

0 commit comments

Comments
 (0)