批处理文件以检查是否已安装Python [英] batch file to check if Python is installed

查看:283
本文介绍了批处理文件以检查是否已安装Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个批处理脚本,该脚本检查是否已安装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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆