Skip to content

env.bat using errorlevels #813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andsch11 opened this issue Mar 4, 2020 · 4 comments
Closed

env.bat using errorlevels #813

andsch11 opened this issue Mar 4, 2020 · 4 comments

Comments

@andsch11
Copy link

andsch11 commented Mar 4, 2020

env.bat (and maybe others) use a line like the following:
echo ";%PATH%;" | %FINDDIR%\find.exe /C /I ";%WINPYDIR%\;" >nul
find.exe sets the system variable ERRORLEVEL to 1 if it does not find anything.

This is an issue if env.bat is used within other scripts depending on the system variable ERRORLEVEL.
Reasons:

  1. after calling env.bat it is now necessary to manually reset the ERRORLEVEL variable
    1.1. NOTE: cannot be done with set ERRORLEVEL=0 (that creates a new variable hiding the orignal one)
  2. after calling env.bat, it is unclear if the errorlevel was set because of some real error in it
@stonebig
Copy link
Contributor

stonebig commented Mar 4, 2020

And so, what do you suggest ?

@andsch11
Copy link
Author

andsch11 commented Mar 5, 2020

Here a small testscript to play around:

@echo off
echo Errolevel: %errorlevel%

echo Verify if "somestring_which_hardly_exists_anywhere" can be found in the path variable
echo ";%PATH%;" | find.exe /C /I ";somestring_which_hardly_exists_anywhere;" >nul
if %errorlevel% neq 0 (
echo do update the path 
echo Reset errorlevel
cd .
)


echo Verify if c can be found in the path variable
echo ";%PATH%;" | find.exe /C /I ";c:\Windows;" >nul
if %errorlevel% neq 0 (
echo we should never be here
goto SOME_ERROR
)

echo Verify that errorlevel is still 0
if %errorlevel% neq 0 (
echo errorlevel must always be 0
goto SOME_ERROR
)




Echo All operations completed successfully
goto FINAL_EXIT

:SOME_ERROR
Echo There was a problem running the script

:FINAL_EXIT
pause
REM Clean errorlevel on exit
cd .

And here my suggestion to patch env.bat

echo ";%PATH%;" | %FINDDIR%\find.exe /C /I ";%WINPYDIR%\;" >nul
if %ERRORLEVEL% NEQ 0 (
set PATH=%WINPYDIR%\Lib\site-packages\PyQt5;%WINPYDIR%\Lib\site-packages\PyQt4;%WINPYDIR%\Lib\site-packages\PySide2;%WINPYDIR%\;%WINPYDIR%\DLLs;%WINPYDIR%\Scripts;%WINPYDIR%\..\t;%WINPYDIR%\..\t\mingw32\bin;%WINPYDIR%\..\t\R\bin\x64;%WINPYDIR%\..\t\Julia\bin;%WINPYDIR%\..\n;%PATH%;
cd .
)

@stonebig
Copy link
Contributor

stonebig commented Mar 5, 2020

Ok. I Will have a look this week-end on this.

@stonebig
Copy link
Contributor

stonebig commented Mar 7, 2020

it doesn't work exactly like that on my PC, it needs this tweak found on stackoverflow, because of parenthesis in the %path%

https://stackoverflow.com/questions/8756828/visual-studio-command-prompt-gives-common-was-unexpected-at-this-time/8756990#8756990

set "var2=%var%"

and so

if %ERRORLEVEL% NEQ 0 (
   set "PATH=%WINPYDIR%\Lib\site-packages\PyQt5;%WINPYDIR%\Lib\site-packages\PySide2;%WINPYDIR%\;%WINPYDIR%\DLLs;%WINPYDIR%\Scripts;%WINPYDIR%\..\t;%WINPYDIR%\..\t\mingw32\bin;%WINPYDIR%\..\t\R\bin\x64;%WINPYDIR%\..\t\Julia\bin;%WINPYDIR%\..\n;%PATH%;"
   cd .
)

Didn't you encounter this problem ?

stonebig added a commit to stonebig/winpython that referenced this issue Mar 7, 2020
@stonebig stonebig mentioned this issue Mar 7, 2020
@stonebig stonebig closed this as completed Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants