Search code examples
pythonbatch-filecmd

Getting and setting variables with .bat/cmd


How can i get the first output of the command where python and include all in the run.bat file ?

where python output:

C:\Users\Vermelhao>where python
C:\Program Files\Python\310\python.exe
C:\Users\Vermelhao\AppData\Local\Microsoft\WindowsApps\python.exe

Desired value "C:\Program Files\Python\310\python.exe"

run.bat

pip install -r requirements.txt
"C:\Program Files\Python\310\python.exe" "./main.py"
pause

I want to assemble the run.bat file in a way that the python.exe path comes from the first path returned by the where python command

i've tried using set path=$(where python) but this holds the value like a string


Solution

  • where python returns the first Python found in the PATH. That is EXACTLY what you would get if you just ran python without specifying a path. So, what you ask is literally the same thing as this:

    pip install -r requirements.txt
    python ./main.py
    pause