将 CertUtil -hashfile 的结果保存到变量并删除散列的空格
Saving result of CertUtil -hashfile to a variable and remove spaces of the hash
我想保存
的结果
CertUtil -hashfile "path_to_file" MD5
到一个变量并删除命令行命令中散列的空格(更具体地说,我想在 post 的命令行中使用它-在 VS 2015 C++ 中处理)。
目前结果如下:
1) C:\Users\admin>CertUtil -hashfile ping.txt MD5
2) MD5 hash of file ping.txt:
3) 4f 75 c2 2c 20 b4 81 54 72 2c a5 7c 95 7a 66 88
4) CertUtil:
-hashfile command completed successfully.
我只需要行 3)
- 将六边形字符串保存到一个变量,然后删除空格。
非常感谢!
你可以用这个准备使用 MD5.bat:
call MD5.bat "path_to_file" md5_var
echo %md5_var%
如果不想要一个全新的单独脚本,您可以只使用 link.
中的最后一个 for 循环
尽管上面有答案,但通常 setlocal enabledelayedexpansion issue
@echo off
setlocal enabledelayedexpansion
set /a count=1
for /f "skip=1 delims=:" %%a in ('CertUtil -hashfile "ping.txt" MD5') do (
if !count! equ 1 set "md5=%%a"
set/a count+=1
)
set "md5=%md5: =%
echo %md5%
endlocal
exit/B
我完全迟到了,但是使用 find 来删除不需要的行怎么样:
CertUtil -hashfile "path_to_file" MD5 | find /i /v "md5" | find /i /v "certutil"
使用 powershell 命令:
$(CertUtil -hashfile C:\TEMP\MyDataFile.img MD5)[1] -replace " ",""
我想保存
的结果CertUtil -hashfile "path_to_file" MD5
到一个变量并删除命令行命令中散列的空格(更具体地说,我想在 post 的命令行中使用它-在 VS 2015 C++ 中处理)。
目前结果如下:
1) C:\Users\admin>CertUtil -hashfile ping.txt MD5
2) MD5 hash of file ping.txt:
3) 4f 75 c2 2c 20 b4 81 54 72 2c a5 7c 95 7a 66 88
4) CertUtil: -hashfile command completed successfully.
我只需要行 3)
- 将六边形字符串保存到一个变量,然后删除空格。
非常感谢!
你可以用这个准备使用 MD5.bat:
call MD5.bat "path_to_file" md5_var
echo %md5_var%
如果不想要一个全新的单独脚本,您可以只使用 link.
中的最后一个 for 循环尽管上面有答案,但通常 setlocal enabledelayedexpansion issue
@echo off
setlocal enabledelayedexpansion
set /a count=1
for /f "skip=1 delims=:" %%a in ('CertUtil -hashfile "ping.txt" MD5') do (
if !count! equ 1 set "md5=%%a"
set/a count+=1
)
set "md5=%md5: =%
echo %md5%
endlocal
exit/B
我完全迟到了,但是使用 find 来删除不需要的行怎么样:
CertUtil -hashfile "path_to_file" MD5 | find /i /v "md5" | find /i /v "certutil"
使用 powershell 命令:
$(CertUtil -hashfile C:\TEMP\MyDataFile.img MD5)[1] -replace " ",""