使用命令行参数在 C# 中运行 exe,抑制 dos 窗口

发布于 2024-08-27 15:05:12 字数 253 浏览 5 评论 0原文

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

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

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

converter.WaitForExit();

I am using lame for transcoding for one of my project. The issue is that when I call lame from C#, a DOS window pops out. Is there any way I can suppress this?

Here is my code so far:

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

converter.WaitForExit();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

染柒℉ 2024-09-03 15:05:12

你有没有尝试过类似的事情:

using( var process = new Process() )
{
    process.StartInfo.FileName = "...";
    process.StartInfo.WorkingDirectory = "...";
    process.StartInfo.CreateNoWindow = true;
    process.StartInfo.UseShellExecute = false;
    process.Start();
}

Did you try something like:

using( var process = new Process() )
{
    process.StartInfo.FileName = "...";
    process.StartInfo.WorkingDirectory = "...";
    process.StartInfo.CreateNoWindow = true;
    process.StartInfo.UseShellExecute = false;
    process.Start();
}
不交电费瞎发啥光 2024-09-03 15:05:12

假设您通过 Process.Start,您可以使用采用 ProcessStartInfo 具有其 CreateNoWindow 属性设置为 true 及其 UseShellExecute 设置为 <代码>假。

ProcessStartInfo 对象也可以通过 Process.StartInfo 属性访问,并且可以在启动进程之前直接设置(如果要设置的属性数量较少,则更容易) 。

Assuming you are calling it via Process.Start, you can use the overload that takes ProcessStartInfo that has its CreateNoWindow property set to true and its UseShellExecute set to false.

The ProcessStartInfo object can also be accessed via the Process.StartInfo property and can be set there directly before starting the process (easier if you have a small number of properties to setup).

幸福丶如此 2024-09-03 15:05:12
Process bhd = new Process(); 
bhd.StartInfo.FileName = "NSOMod.exe";
bhd.StartInfo.Arguments = "/mod NSOmod /d";
bhd.StartInfo.CreateNoWindow = true;
bhd.StartInfo.UseShellExecute = false;

是另一种方式。

Process bhd = new Process(); 
bhd.StartInfo.FileName = "NSOMod.exe";
bhd.StartInfo.Arguments = "/mod NSOmod /d";
bhd.StartInfo.CreateNoWindow = true;
bhd.StartInfo.UseShellExecute = false;

Is another way.

风轻花落早 2024-09-03 15:05:12

这是我的代码,它执行类似的操作(并且还读取输出和返回代码)

        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 

This is my code that does a similar thing, (and also reads the output and return code)

        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 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文