私は自分のプロジェクトの1つでトランスコーディングにlameを使用しています。問題は、C#からlameを呼び出すと、DOSウィンドウがポップアップすることです。これを抑える方法はありますか?
これまでの私のコードは次のとおりです。
Process converter =
Process.Start(lameExePath, "-V2 \"" + waveFile + "\" \"" + mp3File + "\"");
converter.WaitForExit();
次のようなことを試しましたか?
using( var process = new Process() )
{
process.StartInfo.FileName = "...";
process.StartInfo.WorkingDirectory = "...";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.Start();
}
を介して呼び出していると仮定すると、プロパティがに設定され、に設定されてProcess.Start
いるオーバーロードを使用できます。ProcessStartInfo
CreateNoWindow
true
UseShellExecute
false
ProcessStartInfo
オブジェクトにはプロパティを介してアクセスすることもでき、Process.StartInfo
プロセスを開始する直前にそこに設定できます(セットアップするプロパティの数が少ない場合は簡単です)。
Process bhd = new Process();
bhd.StartInfo.FileName = "NSOMod.exe";
bhd.StartInfo.Arguments = "/mod NSOmod /d";
bhd.StartInfo.CreateNoWindow = true;
bhd.StartInfo.UseShellExecute = false;
別の方法です。
これは、同様のことを行う私のコードです(また、出力コードと戻りコードを読み取ります)
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