tags:

views:

370

answers:

4

Hi folks 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 ? thank you


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

        converter.WaitForExit();
+6  A: 

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();
}
tanascius
the process.WaitForExit(); doesn't work quite right if this is used. Is it possible to avoid the Dos window as well as keep the program on hold, until the process terminates ?
Egon
@Egon: what is the problem with WaitForExit();? I am using it and I never had any problems so far.
tanascius
I am using lame to change in file encode. in the next few lines I am playing the newly encoded file. If I do it without the dos window, I cribs saying the said file doesn't exist.
Egon
+3  A: 

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

Oded
+2  A: 
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.

Dremation
+1  A: 

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 
Fiona Holder