当我使用C#执行Mac Os内置命令(例如“ ls”命令)时,通常可以按以下方式返回命令行结果:
string mediaInfo = "";
ProcessStartInfo start = new ProcessStartInfo("ls");
start.Arguments = "-i";
start.CreateNoWindow = false;
start.RedirectStandardOutput = true;
start.RedirectStandardInput = true;
start.UseShellExecute = false;
Process p=Process.Start(start);
StreamReader reader = p.StandardOutput;
string line = reader.ReadLine();
while (!reader.EndOfStream)
{
line = reader.ReadLine();
mediaInfo = line + mediaInfo;
}
p.WaitForExit();
p.Close();
reader.Close();
return mediaInfo;
上面的代码可以返回“ ls”命令的执行结果,但是当我将“ ls”命令更改为“ ffmpeg”时,什么也没有返回。代码如下:(我已经正确安装了ffmpeg,并在命令行上成功执行了
string mediaInfo = "";
ProcessStartInfo start = new ProcessStartInfo("ffmpeg");
start.Arguments = "-i";
start.CreateNoWindow = false;
start.RedirectStandardOutput = true;
start.RedirectStandardInput = true;
start.UseShellExecute = false;
Process p=Process.Start(start);
StreamReader reader = p.StandardOutput;
string line = reader.ReadLine();
while (!reader.EndOfStream)
{
line = reader.ReadLine();
mediaInfo = line + mediaInfo;
}
p.WaitForExit();
p.Close();
reader.Close();
return mediaInfo;
有人知道这是什么吗?非常感谢你!