2017-09-24 104 views
0

我試圖讓我的遊戲啓動器,我喜歡在後臺添加音樂播放器,但如果我開始的過程中,它立即失敗了。c#啓動控制檯應用程序在贏取形式

代碼

private void btnStartMusic_Click(object sender, EventArgs e) 
{ 
    ProcessStartInfo proc = new 
    ProcessStartInfo("MusicPlayer\\MemequickieMusicPlayer.exe"); 
    proc.CreateNoWindow = true; 
    proc.WindowStyle = ProcessWindowStyle.Hidden; 
    proc.RedirectStandardError = false; 
    proc.RedirectStandardInput = false; 
    proc.RedirectStandardOutput = false; 
    proc.UseShellExecute = false; 
    Process.Start(proc); 
} 

任何幫助表示讚賞。

+0

詢問您是否缺少一些信息。 – MemesTV

+0

小心分享錯誤訊息? – Isma

+0

它立即存在,所以我看不到錯誤信息。 – MemesTV

回答

3

嘗試使用exe的完整路徑並設置工作目錄;假設該exe是在你的可執行文件夾:

string path = Path.Combine(Application.StartupPath, "MusicPlayer"); 

ProcessStartInfo proc = new 
    ProcessStartInfo(Path.Combine(path, "MemequickieMusicPlayer.exe")); 

proc.WorkingDirectory = path; 

如果發生錯誤,而且要調試輸出,更改:

proc.RedirectStandardOutput = true; 

創建過程是這樣的:

Process process = new Process(proc); 
process.Start(); 

while (!process.StandardOutput.EndOfStream) { 
    System.Diagnostics.Debug.Write(process.StandardOutput.ReadLine()); 
} 

您現在應該在輸出窗口中看到輸出。

+0

我做了一點不同,但我用它作爲參考。感謝幫助。 – MemesTV