我正在为我的一个项目使用 lame 进行转码。问题是当我从 C# 调用 lame 时,会弹出一个 DOS 窗口。有什么办法可以抑制这个吗?
到目前为止,这是我的代码:
Process converter =
Process.Start(lameExePath, "-V2 \"" + waveFile + "\" \"" + mp3File + "\"");
converter.WaitForExit();
您是否尝试过类似的方法:
using( var process = new Process() )
{
process.StartInfo.FileName = "...";
process.StartInfo.WorkingDirectory = "...";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.Start();
}
假设您通过 调用它Process.Start
,则可以使用将ProcessStartInfo
其CreateNoWindow
属性设置为true
并UseShellExecute
设置为的重载false
。
该ProcessStartInfo
对象也可以通过Process.StartInfo
属性访问,并且可以在开始过程之前直接在那里设置(如果您需要设置少量属性,则更容易)。
Process bhd = new Process();
bhd.StartInfo.FileName = "NSOMod.exe";
bhd.StartInfo.Arguments = "/mod NSOmod /d";
bhd.StartInfo.CreateNoWindow = true;
bhd.StartInfo.UseShellExecute = false;
是另一种方式。
这是我做类似事情的代码,(并且还读取输出和返回代码)
process.StartInfo.FileName = toolFilePath;
process.StartInfo.Arguments = parameters;
process.StartInfo.UseShellExecute = false; // needs to be false in order to redirect output
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true; // redirect all 3, as it should be all 3 or none
process.StartInfo.WorkingDirectory = Path.GetDirectoryName(toolFilePath);
process.StartInfo.Domain = domain;
process.StartInfo.UserName = userName;
process.StartInfo.Password = decryptedPassword;
process.Start();
output = process.StandardOutput.ReadToEnd(); // read the output here...
process.WaitForExit(); // ...then wait for exit, as after exit, it can't read the output
returnCode = process.ExitCode;
process.Close(); // once we have read the exit code, can close the process