phpsh hpcli開發(fā)的終極方案(php版本切換的 批處理)
最近用php代替vbs腳本,做些小工具的開發(fā)。為了方便測(cè)試不同php版本的兼容,專門寫了一個(gè) php版本切換的 批處理 phpsh.cmd,支持安裝到系統(tǒng)、卸載等功能,還支持多個(gè)php版本的任意切換(需要先安裝phpStudy)。
如果需要安裝到系統(tǒng),必須以管理員身份運(yùn)行 命令提示符,基本的使用方法如下:
安裝成功后,就不用使用管理員身份執(zhí)行了??梢栽谌我饽夸?執(zhí)行 phpsh,會(huì)自動(dòng)設(shè)置php環(huán)境。
如果以 非管理員身份執(zhí)行 安裝和卸載,會(huì)有對(duì)應(yīng)的提示。不安裝到系統(tǒng)也可以運(yùn)行:
不安裝時(shí),如果phpsh沒有在當(dāng)前路徑,可以使用完整的路徑名運(yùn)行:
代碼比較簡單,下面時(shí)全部的代碼:
@echo off ::安裝路徑 set ins=C:\Windows\%~nx0 ::如果存在對(duì)應(yīng)的PHP版本,進(jìn)入主程序 if "%1"=="" goto main if "%1"=="52" goto main if "%1"=="53" goto main if "%1"=="53n" goto main if "%1"=="55" goto main if "%1"=="55n" goto main if "%1"=="70n" goto main goto cmds ::主程序 :main set PHP_VER=PHP%1 if "%PHP_VER%" == "PHP" set PHP_VER=PHP55 set path=d:\phpstudy\%PHP_VER%;%path% title %PHP_VER%_sh prompt %PHP_VER%_sh^>$p# goto quit ::如果是輸入的非數(shù)字參數(shù),解析 :cmds if "%1"=="/i" goto install if "%1"=="/install" goto install if "%1"=="/u" goto uninstall if "%1"=="/uninstall" goto uninstall if "%1"=="/v" goto version if "%1"=="/version" goto version goto help ::顯示幫助 :help echo 用法: %~n0 [/h ^| /help ^| /i ^| /install ^| /u ^| /unstall ^| /v ^| /version ^| PHP_VERSION] echo. echo 沒有參數(shù) 設(shè)置php版本為php5.5 echo /h 顯示幫助 echo /help顯示幫助,和/h相同 echo /i 安裝到系統(tǒng) echo /install 安裝到系統(tǒng),和/i相同 echo /u 卸載 echo /unstall 卸載,同/u echo /v 查看當(dāng)前php版本 echo /version 查看當(dāng)前php版本,同/u echo 52 設(shè)置php版本為php5.2 echo 53 設(shè)置php版本為php5.3 echo 53n 設(shè)置php版本為php5.3n echo 55 設(shè)置php版本為php5.5 echo 55n 設(shè)置php版本為php5.5n echo 70n 設(shè)置php版本為php7.0n goto quit ::查看版本 :version php --version goto quit ::安裝 :install echo 開始安裝.. if not exist %ins% copy %~f0 %ins%>nul if %ERRORLEVEL% == 0 echo 安裝成功,打開命令提示符后輸入%~n0即可啟動(dòng) if %ERRORLEVEL% == 1 echo 安裝失敗,必須以管理員模式運(yùn)行 goto quit ::卸載失敗 :uninstallerror echo 卸載失敗,必須以管理員模式運(yùn)行 goto quit ::卸載 :uninstall copy %~f0 %ins%.bak>nul if %ERRORLEVEL% == 1 goto uninstallerror echo 卸載成功 del %ins%.bak>nul if exist %ins% del %ins% :quit
到此這篇關(guān)于phpsh hpcli開發(fā)的終極方案(php版本切換的 批處理)的文章就介紹到這了,更多相關(guān)php版本切換內(nèi)容請(qǐng)搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。