【发布时间】:2020-07-07 08:51:59
【问题描述】:
我想为 server.jar 文件编写一个小更新工具,以节省我手动执行的所有工作 我正在使用的程序会在发布新更新时创建一个包含文件的文件夹。这就是程序的工作原理:
get hash of current server.jar
find latest created folder (eg. update12)
open the file in the update12 folder (eg. update12.txt)
***extract the hash code -> %newHash%*** thats where im having the issue
compare the extracted hashcode (%newHash%) and the calculated hashcode (%currentHash%)
if they are not equal go to www.downloadupdate.com/updates/%newHash%/server.jar
download the file and replace the old server.jar with the new one.
我遇到的问题是我无法读取 update12.txt 中的哈希值,该文件的长度约为 36000 个符号,并且仅在一行中
“服务器”:{“sha1”:“16f18c21286a3f566d3d0431d13aa133bebe6eff”
我想检测 "server": {"sha1": " 部分并在此之后复制哈希 我尝试了在这个论坛上找到的许多选项,但似乎没有一个有效 喜欢这个
set /p txt=<update12.txt
pause >nul
echo %txt%
pause >nul
for /f %%i in ('powershell -noprofile -c "('%txt:"=\"%' -split '\""')[1]"') do set id=%%i
echo %id%
只是导致批处理文件立即关闭 进一步设置 /p txt=
如果您有任何解决方案,我将不胜感激
【问题讨论】:
-
您是从控制台窗口还是从资源管理器运行批处理文件?尝试将
pause放在末尾或从控制台窗口运行它,以便查看输出。 -
您可能超过了 maximum command line length 和/或最大环境变量长度 (32K)。
-
我会在 powershell 中重写整个脚本。
-
您可能正在尝试读取使用 LF 而不是 CRLF 行结尾的文件。当它实际上是多条线时,它可能显示为一条线。你能确认一下吗?
标签: batch-file batch-processing