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

Closed
vbabiy opened this Issue Mar 14, 2011 · 4 comments

Projects

None yet

2 participants

@vbabiy
Contributor
vbabiy commented Mar 14, 2011

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%

@vbabiy
Contributor
vbabiy commented Mar 14, 2011

Original Comment By: s4g
@vbabiy
Contributor
vbabiy commented Mar 14, 2011
  • Changed content.

Original Comment By: s4g
@vbabiy
Contributor
vbabiy commented Mar 14, 2011

This is a duplicate of #3, this should be fixed in tip

Duplicate of #3.

are


Original Comment By: Philip Jenvey
@uweschmitt

I still have this problem. Was the fix included in virtualenv ?

@Ivoz Ivoz added a commit that referenced this issue Jan 19, 2016
@Ivoz Ivoz Remove some brackets in bat, solves #35 227a511
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment