我使用lame進行我的項目之一的代碼轉換。問題是,當我從C#調用跛腳時,會彈出一個DOS窗口。有什麼辦法可以壓制這個嗎?使用命令行參數在C#中運行exe,抑制dos窗口
這裏是我到目前爲止的代碼:
Process converter =
Process.Start(lameExePath, "-V2 \"" + waveFile + "\" \"" + mp3File + "\"");
converter.WaitForExit();
我使用lame進行我的項目之一的代碼轉換。問題是,當我從C#調用跛腳時,會彈出一個DOS窗口。有什麼辦法可以壓制這個嗎?使用命令行參數在C#中運行exe,抑制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
如何向我們展示一些代碼? – 2010-03-30 14:39:04