C# 通过命令行实现--文件 MD5返回值
public string runCmdBack(string cmd)
{
StringBuilder builder = new StringBuilder();
try
{
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
//执行命令
process.StartInfo.Arguments = $"/C {cmd}";
process.StartInfo.UseShellExecute = false;//不启用shell
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;//不使用窗口
process.Start();
StreamReader reader = process.StandardOutput;
string line = "";//每次读取一行
while ((line = reader.ReadLine()) != null)
{
//Console.WriteLine(">>" + line);
builder.AppendLine(line);
}
process.WaitForExit();
process.Close();
reader.Close();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return builder.ToString();
}
入参:certutil -hashfile c:\3d4596eb-6f99-4e9f-bb68-a8672cb5dd46.pdf md5
返回值:

博客内容主要用于日常学习记录,内容比较随意,如有问题,还需谅解!!!