我正在尝试获取进程信息并得到两个错误,我该如何解决它们
本文关键字:两个 错误 解决 何解决 获取 取进程 信息 | 更新日期: 2023-09-27 18:27:35
private void ProcessInfo()
{
string ffMPEG = System.IO.Path.Combine(Application.StartupPath, "ffMPEG.exe");
System.Diagnostics.Process mProcess = null;
System.IO.StreamReader SROutput = null;
string outPut = "";
string filepath = "D:''source.mp4";
string param = string.Format("-i '"{0}'"", filepath);
System.Diagnostics.ProcessStartInfo oInfo = null;
System.Text.RegularExpressions.Regex re = null;
System.Text.RegularExpressions.Match m = null;
TimeSpan Duration = 0;
//Get ready with ProcessStartInfo
oInfo = new System.Diagnostics.ProcessStartInfo(ffMPEG, param);
oInfo.CreateNoWindow = true;
//ffMPEG uses StandardError for its output.
oInfo.RedirectStandardError = true;
oInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
oInfo.UseShellExecute = false;
// Lets start the process
mProcess = System.Diagnostics.Process.Start(oInfo);
// Divert output
SROutput = mProcess.StandardError;
// Read all
outPut = SROutput.ReadToEnd();
// Please donot forget to call WaitForExit() after calling SROutput.ReadToEnd
mProcess.WaitForExit();
mProcess.Close();
mProcess.Dispose();
SROutput.Close();
SROutput.Dispose();
//get duration
re = new System.Text.RegularExpressions.Regex("[D|d]uration:.((''d|:|''.)*)");
m = re.Match(outPut);
if (m.Success)
{
//Means the output has cantained the string "Duration"
string temp = m.Groups(1).Value;
string[] timepieces = temp.Split(new char[] { ':', '.' });
if (timepieces.Length == 4)
{
// Store duration
Duration = new TimeSpan(0, Convert.ToInt16(timepieces[0]), Convert.ToInt16(timepieces[1]), Convert.ToInt16(timepieces[2]), Convert.ToInt16(timepieces[3]));
}
}
}
该行的错误:
TimeSpan Duration = 0;
我无法将其重置为 0,我也无法为其分配 null。
错误 3 无法将类型"int"隐式转换为"System.TimeSpan">
该行的第二个错误:
string temp = m.Groups(1).Value;
错误 4 不可调用成员 "System.Text.RegularExpressions.Match.Groups"不能像 方法。
由于0
是int
,所以没有隐式对话来TimeSpan
。您可以改用TimeSpan.Zero
。
TimeSpan Duration = TimeSpan.Zero;
而且由于Match.Groups
是一个属性,因此您需要将其与不喜欢()
[]
一起使用;
string temp = m.Groups[1].Value;