実際のコマンド プロンプトでの出力は次のようになります。
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
(like )を使用できますresult.IndexOf("Version:");
- しかし、それではバージョンの値がわかりません
どんな考えも役に立ちます。