Try to create a Windows .bat file to achieve the below function:
cd C:\repo\demo
venv\Scripts\activate
python test.py
In Visual Studio Code terminal window, I can run the above lines without issue.
Created a .bat file as below:
cd C:\repo\demo
"C:\Users\jw\AppData\Local\Programs\Python\Python310\python.exe" "venv\Scripts\activate"
"C:\Users\jw\AppData\Local\Programs\Python\Python310\python.exe" "python test.py"
pause
When double click the above .bat file to run it, end with error:
if [ "${BASH_SOURCE-}" = "$0" ]; then
SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
Also tried the below .bat code, not working either:
cd C:\repo\demo
venv\Scripts\activate
python test.py
pause
How to correct the .bat file to make it work?
======================================
Based on @Compo's comment, tried the below version and it successfully executed python test.py
:
cd C:\repo\demo
call "venv\Scripts\activate.bat"
python test.py
pause
but seems it didn't finish call "venv\Scripts\activate.bat"
, the command line window shows as below:
When manually run the code, it will prefix the path with (venv) as below which shows the proper result:
============================================
UPDATE:
The below .bat version works now, an answer from this question
cd C:\repo\demo && call "venv\Scripts\activate.bat" && python test.py && pause