好吧,即時消息不會繞過它,並在我正在做的事情上跳舞。 直升起來,即時嘗試爲C#中的虛幻開發工具包製作GUI UnrealScript編譯器。確切的本質是更大的事情,但是這是發生了什麼:C# - 從一個新進程的子窗口捕獲輸出
我開始啓動一個新的進程的新的線程,併成立了一個StreamReader使得具有監聽器來捕獲輸出,它被寫入到控制檯窗口。 這不是一個問題,除了在啓動UDK.exe make
時似乎產生了一個子控制檯窗口,這就是實際的編譯器。 如果我CD
到我UDK/Binaries/Win32
目錄,並做UDK.exe make >> output.txt
絕對沒有得到書面的命令,但該文件被創建(當然編譯器往往運行以及)
我使用(只要我能告訴)線程安全操作來訪問我的輸出文本框,我想寫在編譯器正在運行。
繼承人我的代碼:
public partial class ProjectEditor : Form
{
delegate void SetTextCallback(string text);
/*** ... other completely unrealted code ... ***/
private void Menu_Project_Compile_JustCompile_Click(object sender, EventArgs e) {
Thread compile = new Thread(
new ThreadStart (
this.Compile
)
);
NewConsoleLine("Starting Compiler New");
compile.Start();
}
////////
private void Compile() {
this.RunWithRedirect(FileMan.getUDK(), " make");
}
void RunWithRedirect(string cmdPath, string args = null) {
var proc = new Process();
proc.StartInfo.FileName = cmdPath;
proc.StartInfo.Arguments = args;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.EnableRaisingEvents = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.ErrorDataReceived += proc_DataReceived;
proc.OutputDataReceived += proc_DataReceived;
proc.Start();
proc.BeginErrorReadLine();
proc.BeginOutputReadLine();
proc.WaitForExit();
}
void proc_DataReceived(object sender, DataReceivedEventArgs e) {
NewConsoleLine(e.Data);
}
void NewConsoleLine(String text) {
if (this.OutputConsole.InvokeRequired) {
SetTextCallback d = new SetTextCallback(NewConsoleLine);
this.Invoke(d, new object[] { text });
} else {
OutputConsole.Text += text + "\n";
}
}
}
此刻,當我執行編譯的方法,我的控制檯被寫入行Starting Compiler New
和UDK.exe控制檯窗口中顯示出來,並沒有輸出掛在那兒看起來永遠都是。
有沒有人有任何見識,如何調整我的流光擷取實際輸出? 我知道這是可能的,因爲我已經看到其他的UnrealScript IDE實現這種效果(沒有彈出窗口,實時寫入控制檯窗口的全部輸出) 我可以感覺到我很接近,但即時通訊尚未完成。 ...
........................................ THERES A .COM?!!? !我怎麼沒有看到這個!哦,我的GAWD是的,你剛剛救了我幾個小時的頭痛和折磨! :D(還沒試過,但我確定這是魔術門票) – RedactedProfile 2012-03-21 21:31:17
這絕對有效,我非常感謝你。我開始非常沮喪 – RedactedProfile 2012-03-22 16:43:16
沒有問題。 :) – Phillip 2012-03-23 14:31:52