I'm trying to replace a certain .jar file if the MD5 hash of the file changes. I've written a small PowerShell script to do the hashing of the file and the .ps1 script is run through a batch file.
After PowerShell prints the hash into 1.txt
I want the batch script to check the text file for the correct hash and if the hash is different it will overwrite the file with the old version. The replacing of the file is not yet implemented but will be once the findstr
issue is resolved.
@echo off
setlocal EnableDelayedExpansion
:a
powershell.exe -ExecutionPolicy ByPass -file powershellmd5.ps1
findstr /c:"ff b1 b9 2d b1 03 db 59 3f 9e ca 51 f0 14 67 62 ca a8 d7 7d" "1.txt"
echo !errorlevel!
timeout /t 10 /NOBREAK
goto a
Here is the content of 1.txt
when the hashing is complete:
SHA1 hash of file license.jar:
ff b1 b9 2d b1 03 db 59 3f 9e ca 51 f0 14 67 62 ca a8 d7 7d
CertUtil: -hashfile command completed successfully.
The errorlevel is always 1, even though the string is identical to the one in the text file. Maybe I am using the arguments wrong?
I'm using Out-File
in powershellmd5.ps1
to write the result:
certutil -hashfile license.txt | Out-File 1.txt
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…