我在实际的命令提示符下输出看起来是这样的:命令行输出验证
Name: My Software
Version: 1.0.1
Installed location: c:\my folder
我试图通过C#代码
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + "my command to execute");
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
string[] lines = result.Split(new string[] { System.Environment.NewLine, }, System.StringSplitOptions.None);
foreach (string tmp in lines)
{
if (tmp.Contains("Version"))
{
isAvailable= true;
}
}
我不想得到这个输出只是检查一个版本标记,我试图获取版本值并进行比较,例如,如果值为1.0.1,我想要该值并与2.0.0进行比较。
我可以使用indexof
(如result.IndexOf("Version:");
) - 但是,这并不让我的版本
值的任何想法会有所帮助。
上面的代码给了我版本值,所有答案都很有帮助,谢谢大家。 – Sharpeye500