Egon
Egon

Reputation: 3848

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

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

Upvotes: 2

Views: 2643

Answers (4)

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 

Upvotes: 2

Art W
Art W

Reputation: 2038

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.

Upvotes: 3

Oded
Oded

Reputation: 499312

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

Upvotes: 3

tanascius
tanascius

Reputation: 53964

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

Upvotes: 8

Related Questions