批处理文件以检查是否已安装Python [英] batch file to check if Python is installed
问题描述
我已经编写了一个批处理脚本,该脚本检查是否已安装Python,是否尚未安装-它会启动Python安装程序,该安装程序与其自身所在的文件夹相同.
I've written a batch script that checks if Python is installed, if it's not installed - it initiates the Python installer contained in the same folder as itself.
我正在使用以下代码:
reg query "hkcu\software\Python 2.6"
if ERRORLEVEL 1 GOTO NOPYTHON
:NOPYTHON
ActivePython-2.6.4.8-win32-x86.msi
reg query "hklm\SOFTWARE\ActiveState\ActivePerl\" 1>>Output_%date%_%time%.log 2>&1
if ERRORLEVEL 1 GOTO NOPERL
reg query "hklm\SOFTWARE\Gtk+"
if ERRORLEVEL 1 GOTO NOPYGTK
:NOPERL
ActivePerl-5.10.1.1006-MSWin32-x86-291086.msi 1>>Output_%date%_%time%.log 2>&1
:NOPYGTK
pygtk_windows_installer.exe
但是在某些情况下,即使安装了Python,安装程序也会启动.这是什么问题?
But in some cases the installer starts up even if Python is installed. What is the problem here?
推荐答案
完成注册表查询后,您的代码不会分支.不管第一个if ERRORLEVEL
评估结果如何,下一步始终是进入:NOPYTHON
标签.
Your code doesn't branch after the registry query is done. No matter what the first if ERRORLEVEL
evaluates to, the next step is always to step into the :NOPYTHON
label.
Ed:这是一个使它工作的示例.想法是添加另一个goto语句,该语句将在需要时跳过:NOPYTHON
标签.
Ed: Here is an example how to make it work. The idea is to add another goto statement which will skip the :NOPYTHON
label if desired.
reg query "hkcu\software\Python 2.6"
if ERRORLEVEL 1 GOTO NOPYTHON
goto :HASPYTHON
:NOPYTHON
ActivePython-2.6.4.8-win32-x86.msi
:HASPYTHON
reg query "hklm\SOFTWARE\ActiveState\ActivePerl\" 1>>Output_%date%_%time%.log 2>&1
这篇关于批处理文件以检查是否已安装Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!