开发者

Running an exe in C# with commandline parameters, suppressing the dos window

I am using lame for transcodi开发者_开发百科ng 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();


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();
}


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).


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.


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 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜