python / cpython

The Python programming language
https://www.python.org
Other
63.12k stars 30.22k forks source link

Batch activators unexpectedly turn echo off for subsequent commands #96894

Open pawelszramowski opened 2 years ago

pawelszramowski commented 2 years ago

Bug report

Consider the following batch script:

python -m venv venv
CALL venv\Scripts\activate.bat
REM spam
CALL deactivate.bat
REM eggs

The expected output is:

W:\>python -m venv venv

W:\>CALL venv\Scripts\activate.bat

(venv) W:\>REM spam

(venv) W:\>CALL deactivate.bat

W:\>REM eggs

The actual output is:

W:\>python -m venv venv

W:\>CALL venv\Scripts\activate.bat

This is caused by @echo off at the beginning of both scripts that need to be undone after calling them:

python -m venv venv
CALL venv\Scripts\activate.bat
@ECHO ON
REM spam
CALL deactivate.bat
@ECHO ON
REM eggs

Your environment

Linked PRs

eryksun commented 2 years ago

If echo off isn't used, then individual statements have to be prefixed with @ to prevent echoing them. I just implemented this for the new versions of "activate.bat" and "deactivate.bat" that were proposed in issue #88706. Note that ending with echo on would be just as bad, since the caller may have it off. I haven't seen a way to detect the current echo state that doesn't involve ugly hacks such as writing to a temporary file.