Manish Test
Manish Test

Reputation: 9

Batch File for installing python and running script

I am writing utility which does the following things:

  1. Check Python has installed it or not. if Not Installed, Script downloads the python and install it. In the same session, it executes the python script.

But I am facing one issue here, as soon as the script install python, it's throwing an error while executing the python script as python is not recognized in cmd. But if I run the same program again it works fine.

The problem here is - after installation of Python, the command prompt is not identifying the python command unless I restart the window.

is there any way?

Script is: Getting error at below highlighted section

:errorNoPython

echo.
echo Error^: Python not installed
echo.
echo.
echo Downloading Python 3.7.0...
IF EXIST "%CD%\python-3.7.0.exe" (
  echo Found Installer at "%CD%\python-3.7.0.exe"
) ELSE (
  powershell -Command "& {[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Ssl3, [Net.SecurityProtocolType]::Tls; Invoke-WebRequest -Uri 'https://www.python.org/ftp/python/3.7.0/python-3.7.0.exe' -OutFile '%CD%\python-3.7.0.exe';}"
  echo Python download completed.
)

echo Installing Python...
powershell %CD%\python-3.7.0.exe /quiet InstallAllUsers=0 PrependPath=1 Include_test=0 TargetDir=c:\Python\Python370
setx path "%PATH%;C:\Python\Python370\"

timeout /t 30 /nobreak > nul
echo Python Installation completed.
echo Installing python dependencies.
**start cmd /k python -m pip install requests
start cmd /k python -m pip install pyjavaproperties**

Upvotes: 0

Views: 2694

Answers (1)

user7818749
user7818749

Reputation:

In order to reload the environment, you have to close and open cmd.exe

So to get around it, you can set the path and setx

Copy exactly as is, but this will set the path in the current environment:

setx path "%PATH%;C:\Python\Python370\"
set "path=%PATH%;C:\Python\Python370\"

Upvotes: 1

Related Questions