hi i have a question how can run a python script in Batch file
i have a setup file for my flask app and every time should set up some environment variable and run app.py
i create a setup for this but i don't know how run python app and it's not working
my setup.cmd file looks like this:
set app_debug=True
set API_KEY=secret
set SECRET_KEY=development mode
set WTF_CSRF_SECRET_KEY=development mode
set email_password=development mode
set RECAPTCHA_PUBLIC_KEY=secret
set RECAPTCHA_PRIVATE_KEY=secret
./venv/Scripts/activate.bat
python app.py
and it's goes to ./venv/Scripts/activate.bat and then stop and don't work
CodePudding user response:
I think you have to “call” an external batch file if you want execution to return your current batch file. So write
call ./venv/Scripts/activate.bat
in your batch file.
CodePudding user response:
Consider having a .env
file to store your environment variables.
From your app.py
file you can load those env vars.
Reference: https://towardsdatascience.com/environment-variables-python-aecb9bf01b85
Example:
import os
env_var = os.environ.get('ENV')
if not env_var:
print('ENV environment variable does not exist')