将CertUtil -hashfile的结果保存到变量并删除哈希的空格 [英] Saving result of CertUtil -hashfile to a variable and remove spaces of the hash

查看:236
本文介绍了将CertUtil -hashfile的结果保存到变量并删除哈希的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要保存

CertUtil -hashfile "path_to_file" MD5

到变量并在命令行命令中删除哈希的空格(更具体地说,我希望在VS 2015 C ++的后处理命令行中使用它).

to a variable and remove spaces of the hash in command line command (to be more particular, I wan to use this in Command Line of post-processing in VS 2015 C++).

当前结果如下:

1)C:\ Users \ admin> CertUtil -hashfile ping.txt MD5
2)文件ping.txt的MD5哈希:
3)4f 75 c2 2c 20 b4 81 54 72 2c a5 7c 95 7a 66 88
4)CertUtil: -hashfile命令成功完成.

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)-将十六进制字符串保存到变量,然后删除空格. 非常感谢!

I just need the line 3) - save the hexa string to a variable and then remove the spaces. Thanks a lot!

推荐答案

尽管有上述答案,但通常还是 setlocal enabledelayedexpansion 问题

Despite the answer above, typicall 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

这篇关于将CertUtil -hashfile的结果保存到变量并删除哈希的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆