Skip to content

Instantly share code, notes, and snippets.

@scw
Created August 8, 2017 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scw/0fa9537df1352d38dcf292b3ebd7afb7 to your computer and use it in GitHub Desktop.
Save scw/0fa9537df1352d38dcf292b3ebd7afb7 to your computer and use it in GitHub Desktop.
Use call instead of invoking separate cmd.exe
@setlocal enabledelayedexpansion
@echo off
@CALL :normalizepath scripts_path "%~dp0"
@set env_text="%scripts_path%proenv.txt"
:: read the activte environment name
@set /p CONDA_NEW_ENV=<%env_text%
@set CONDA_SKIPCHECK=1
@set "CONDA_PREFIX=%CONDA_NEW_ENV%"
:: change directory if started from shortcut
set cwd="%cd%"
set shortcut=0
@IF /I %cwd% == "C:\windows\system32" (
@set shortcut=1
)
@IF NOT x%cwd:Start Menu=% == x%cwd% (
set shortcut=1
)
@SET "activate_path="%scripts_path%activate.bat" "%CONDA_NEW_ENV%""
:: pass activate path through endlocal barrier
@for /f "delims=" %%A in (""!activate_path!"") do (
if %shortcut% == 0 (
@endlocal & @set "CONDA_SKIPCHECK=1" & call %%~A
) else (
@endlocal & @set "CONDA_SKIPCHECK=1" & @cd %CONDA_PREFIX% & cmd.exe /k "%%~A"
)
)
@goto :eof
:normalizepath
@SET "%1=%~dpfn2"
@EXIT /B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment