Batch file 如何批量比较下载的内容
因此,最近,我设计了一个更新检查器,如果web上的Batch file 如何批量比较下载的内容,batch-file,download,Batch File,Download,因此,最近,我设计了一个更新检查器,如果web上的version.txt不等于本地字符串,它将下载并执行更新脚本。我已经在bash中使用cURL和if语句实现了这一点 #bash实现 echo-n“检查更新…” 向上=$(卷曲)https://raw.githubusercontent.com/aaronliu0130/trashBin/master/version) 如果[$up!=“v0.2.0-alpha”];然后 清楚的 echo“找到更新。正在更新。更新后将重新启动。” curl-o
version.txt
不等于本地字符串,它将下载并执行更新脚本。我已经在bash中使用cURL和if语句实现了这一点
#bash实现
echo-n“检查更新…”
向上=$(卷曲)https://raw.githubusercontent.com/aaronliu0130/trashBin/master/version)
如果[$up!=“v0.2.0-alpha”];然后
清楚的
echo“找到更新。正在更新。更新后将重新启动。”
curl-o update.shhttps://raw.githubusercontent.com/aaronliu0130/trashBin/master/update.sh
bash update.sh
出口
fi
现在我正试图在windows批处理中实现这一点。但是,我找不到一种方法将文件下载到cURL之类的变量,或者将文件内容与神奇字符串进行比较。如何批量执行上述代码?尝试以下操作:
@echo off
del /q version.txt >nul 2>&1
bitsadmin /transfer myDownloadJob /download /priority normal https://raw.githubusercontent.com/aaronliu0130/trashBin/master/version %cd%\version.txt
for /f "tokens=* delims=" %%v in (version.txt) do set "version=%%v"
if "%version%" NEQ "v0.2.0-alpha" (
echo update has been found.
bitsadmin /transfer myDownloadJob /download /priority normal https://raw.githubusercontent.com/aaronliu0130/trashBin/master/update.sh %cd%\update.sh
rem if you have linux subsystems for windows installed you can run the line bellow
rem bash update.sh
)
您无法直接将下载的内容加载到内存中,因此您必须依赖临时文件。看起来不错,但您能告诉我它是如何工作的吗?特别是for循环语句。@Aaron-bitsadmin是microsoft提供的用于在windows中下载文件的命令
FOR
用于读取文件内容-您可以找到更多信息。