我正在使用lame进行代码转换我的一个项目。问题是,当我从C#调用lame时,会弹出一个DOS窗口。有什么方法可以抑制这个吗?
到目前为止,这是我的代码:
Process converter =
Process.Start(lameExePath, "-V2 \"" + waveFile + "\" \"" + mp3File + "\"");
converter.WaitForExit();
答案 0 :(得分:8)
您尝试过类似的事情吗?
using( var process = new Process() )
{
process.StartInfo.FileName = "...";
process.StartInfo.WorkingDirectory = "...";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.Start();
}
答案 1 :(得分:3)
假设您是通过Process.Start
调用它,则可以使用将ProcessStartInfo
属性设置为true
的{{3}}及其CreateNoWindow
的重载设为false
。
ProcessStartInfo
对象也可以通过Process.StartInfo
属性访问,并且可以在开始处理之前直接设置(如果您要设置少量属性,则更容易)。
答案 2 :(得分:3)
Process bhd = new Process();
bhd.StartInfo.FileName = "NSOMod.exe";
bhd.StartInfo.Arguments = "/mod NSOmod /d";
bhd.StartInfo.CreateNoWindow = true;
bhd.StartInfo.UseShellExecute = false;
是另一种方式。
答案 3 :(得分:2)
这是我执行类似操作的代码(并且还读取输出和返回代码)
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