2

我正在为我的一个项目使用 lame 进行转码。问题是当我从 C# 调用 lame 时,会弹出一个 DOS 窗口。有什么办法可以抑制这个吗?

到目前为止,这是我的代码:

Process converter =
    Process.Start(lameExePath, "-V2 \"" + waveFile + "\" \"" + mp3File + "\"");

converter.WaitForExit();
4

4 回答 4

8

您是否尝试过类似的方法:

using( var process = new Process() )
{
    process.StartInfo.FileName = "...";
    process.StartInfo.WorkingDirectory = "...";
    process.StartInfo.CreateNoWindow = true;
    process.StartInfo.UseShellExecute = false;
    process.Start();
}
于 2010-03-30T14:39:54.470 回答
3

假设您通过 调用它Process.Start,则可以使用将ProcessStartInfoCreateNoWindow属性设置为trueUseShellExecute设置为的重载false

ProcessStartInfo对象也可以通过Process.StartInfo属性访问,并且可以在开始过程之前直接在那里设置(如果您需要设置少量属性,则更容易)。

于 2010-03-30T14:40:18.927 回答
3
Process bhd = new Process(); 
bhd.StartInfo.FileName = "NSOMod.exe";
bhd.StartInfo.Arguments = "/mod NSOmod /d";
bhd.StartInfo.CreateNoWindow = true;
bhd.StartInfo.UseShellExecute = false;

是另一种方式。

于 2010-03-30T14:40:38.177 回答
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 
于 2010-03-30T15:18:39.007 回答