Skip to content

activate.bat and deactivate.bat fail on 64-bit windows #35

@vbabiy

Description

@vbabiy

Problem:

On a 64-bit windows deactivate.bat fails with the following message:

 \xxxxx was unexpected at this time 

where xxxxx is a subfolder in the "%systemdrive%\Program Files (x86)" folder.

activate.bat will also fail if run a second time in a row.

A precondition to this failure is an application installed in the "%systemdrive%\Program Files (x86)" folder, which is added to the path.

Cause:

Consider the following piece of a batch file:

if defined path ( echo %path% ) 

cmd.exe will expand the %path% variable, then find the closing parenthesis within and consider it the end of if-defined operator.
Then it will complain about the remaining part and exit.

Solution:

Don't use the above mentioned form of if operator with parentheses. For example, the following files work fine:

=================>> deactivate.bat

@echo off if not defined _OLD_VIRTUAL_PROMPT goto NOVPROMPT set PROMPT=%_OLD_VIRTUAL_PROMPT% set _OLD_VIRTUAL_PROMPT= :NOVPROMPT if not defined _OLD_VIRTUAL_PATH goto END set PATH=%_OLD_VIRTUAL_PATH% set _OLD_VIRTUAL_PATH= :END 

================>> activate.bat

@echo off set VIRTUAL_ENV=c:\virtualenv\aaaaa if not defined PROMPT ( set PROMPT=$P$G ) if not defined _OLD_VIRTUAL_PROMPT goto NOVPROMPT set PROMPT=%_OLD_VIRTUAL_PROMPT% :NOVPROMPT set _OLD_VIRTUAL_PROMPT=%PROMPT% set PROMPT=(aaaaa) %PROMPT% if not defined _OLD_VIRTUAL_PATH goto NOVPATH set PATH=%_OLD_VIRTUAL_PATH% :NOVPATH set _OLD_VIRTUAL_PATH=%PATH% set PATH=%VIRTUAL_ENV%\Scripts;%PATH% 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions