我正在项目中使用LAME命令行mp3编码器。 我希望能够看到某人正在使用的版本。 如果我只是执行LAME.exe没有参数,我得到,例如:
C:\LAME>LAME.exe LAME 32-bits version 3.98.2 (http://www.mp3dev.org/) usage: blah blah blah blah C:\LAME>
如果我尝试redirect输出到一个文本文件使用>到一个文本文件的文本文件是空的。 在c#中使用System.Process运行它时,可以从哪里获得此文本?
这可能是使用stderr。 cmd.exe不允许你重定向stderr,唯一的办法就是用djgpp工具重定向它。
它可以输出到stderr而不是stdout。 您可以通过执行以下操作重定向stderr :
LAME.exe 2> textfile.txt
如果这显示你的信息,那么LAME输出到标准的错误流。 如果您使用C#编写包装器,则可以从ProcessStartInfo重定向标准错误和输出流。
System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = @"C:\LAME\LAME.exe"; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.UseShellExecute = false; proc.Start(); string output = proc.StandardError.ReadToEnd(); proc.WaitForExit(); MessageBox.Show(output);
工作。 感谢所有!
它可能被发送到stderr,你有没有尝试过?
检查Process.StandardError 。
试用一下
C:\LAME>LAME.exe 2> test.txt